يمكن اختصار الوقت في الوصولي الي الملف في كل مرا اختار بها قسم معين غير هذا الكود ::
<!DOCTYPE html>
<html>
<head>
<style>
.subsection option{
display:none;
}
.subsection option.active{
display: block;
}
</style>
<script type="text/javascript">
// Mahmmoud Developer ...
window.onload = function() {
var sections = document.querySelector(".sections");
sections.onchange = function () {
var secId = this.value;
var s_Sections = document.querySelectorAll(".subsection>option");
var x = 0;
while (x < s_Sections.length) {
if(s_Sections[x].dataset.secid == secId){
s_Sections[x].classList.add("active");
}
else{
s_Sections[x].classList.remove("active");
}
x++;
}
document.querySelectorAll(".subsection>option[data-secid="+secId+"]")[0].setAttribute("selected",true);
}
}
</script>
</head>
<body>
<select class="sections">
<option value="sec1">section1</option>
<option value="sec2">section2</option>
<option value="sec3">section3</option>
<option value="sec4">section4</option>
</select>
<select class="subsection">
<option value="sub1" data-secid="sec1" class="active">SubSec1-1</option>
<option value="sub2" data-secid="sec1" class="active">SubSec1-2</option>
<option value="sub3" data-secid="sec1" class="active">SubSec1-3</option>
<option value="sub1" data-secid="sec2">SubSec2-1</option>
<option value="sub2" data-secid="sec2">SubSec2-2</option>
<option value="sub3" data-secid="sec2">SubSec2-3</option>
<option value="sub1" data-secid="sec3">SubSec3-1</option>
<option value="sub2" data-secid="sec3">SubSec3-2</option>
<option value="sub2" data-secid="sec3">SubSec3-3</option>
</select>
</body>
</html>
يمكنك تجربة الكود من هنا :
https://www.w3schools.com/code/tryit.asp?filename=FPK1QMD4B47O