My website ends in ...MVR/MVRView.aspx and it doesn't load another page and loads elements within the same HTML using onchange() or options. Selected='selected'.
Website menus:
- Registration Office names: dropdown menu
- Circle names: dropdown menu
- Thana codes: dropdown menu
Only an option selection and onchange() from office_names menu allows circle_names select dropdown menu to show its options, and a circle_names option selection to show thana_codes menu otherwise, it stays empty.
I'm trying to test the code below in my browser console. The code is supposed to switch between the 4 circle_names options for office_names.selectedIndex = 2 to load and show the thana_codes select options element for each. But it randomly selects a circle_names option and shows its loaded thana_codes options element 4 times.
E.g. The option 4 of circle_names element gets selected randomly.
<select name="ctl00$ContentPlaceHolder1$ddl_circle" onchange="javascript:setTimeout('__doPostBack(
\'ctl00$ContentPlaceHolder1$ddl_circle\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddl_circle" class="iddll">
<option value="0">--SELECT--</option>
<option value="06">AMOUR</option>
<option value="07">DAGARUA</option>
<option value="08">BAISI</option>
<option selected="selected" value="09">BAISA</option>
</select>
E.g. The thana_codes element below that loads after circle_names element option 4 selection.
<select name="ctl00$ContentPlaceHolder1$ddl_thanaCode" onchange="javascript:setTimeout('__doPostBack(
\'ctl00$ContentPlaceHolder1$ddl_thanaCode\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddl_thanaCode"
class="iddll">
<option selected="selected" value="0">--SELECT--</option>
<option value="013">Abhaypur/013</option>
<option value="049">Alinagar/049</option>
<option value="002">Arhal/002</option>
<option value="028">Ashiyani/028</option>
<option value="015">Asja/015</option>
<option value="116">Baies Mara/116</option>
<option value="026">Bairgachhi/026</option>
.......................................
<option value="031">Sukarna/031</option>
<option value="107">Tarabari/107</option>
<option value="096">Tetaliya/096</option>
<option value="020">Titiha/020</option>
<option value="038">Ufrail/038</option>
</select>
I want a loop that switches between the circle_names options and gives 4 unique thana_codes elements instead of repeating the above one 4 times.
Code:
var office_names = document.getElementById(
"ctl00_ContentPlaceHolder1_ddl_dsro"
);
office_names.selectedIndex = 2;
office_names.onchange();
circle_names = document.getElementById("ctl00_ContentPlaceHolder1_ddl_circle");
for (let i = 1; i < circle_names.options.length; i++) {
const option = circle_names.options[i];
option.selected = "selected";
if (option.selected) {
console.log(
document.getElementById("ctl00_ContentPlaceHolder1_ddl_thanaCode")
);
}
}
The code works for a single circle_names option for office_names option 2. In the loop version, I also tried to add time delays, but it didn't work.
How can I get the thana_codes element for each circle_names in the browser console?