[Code]
$.ajax
({
'method': 'GET',
'source': '/bpv-registratie/periods/show_period_list_by_year.html',
'charge': function ()
{
},
'finish': function (xmlHttp)
{
var options = new Array();
var response = eval('(' + xmlHttp.responseText + ')');
var child = document.createElement('option');
child.setAttribute('value', 'none');
child.setAttribute('checked', 'checked');
child.innerHTML = ' ';
options.push(child);
for (var c = 0; c < response.length; c++)
{
var child = document.createElement('option');
child.setAttribute('value', response.data[c].periode_id);
child.innerHTML = response.data[c].periode_naam +
' (' +
response.data[c].periode_startdatum +
' t/m ' +
response.data[c].periode_einddatum +
' )';
options.push(child);
}
for (var a = 0; a < obj.childNodes.length; a++)
{
var e = obj.childNodes[a].getElementsByTagName("select");
for (var f = 0; f < e.length; f++)
{
e[f].length=0;
for (var o = 0; o < options.length; o++)
{
e[f].appendChild(options[o]);
}
}
alert('test');
}
}
});
[Problem]
Upon running the aforementioned code with the alert, it indicates that all select boxes are getting filled with the desired options. However, when it proceeds to fill the next select box, the previous one gets cleared again. Any insights on why this is happening?
[Situation]
A series of select boxes have been generated using similar code. These represent classes that an individual can be enrolled in. The user must select a class from these select boxes. Nevertheless, if an instructor wishes to switch the person to a different period, which likely entails having different classes available during that time, my goal is to populate the select boxes with classes from the new period.