On a form there are 2 select lists. One is dependant of the value of the other. Let's say: car brand and model. If you choose a brand in the first list, the appropriate list of models for that particular brand is retrieved from the server and the second list is populated.After populating the list a seletedIndex must be set. This is where it all goes wrong. Here is some relevant coding:
function loadModel(iBrandNr) { var srcRequest = new XMLHttpRequest(); var sGet = '../lib/handleModel.php?brand_nr='+iBrandNr; srcRequest.open('GET', sGet,false); srcRequest.send(null); replaceList('selModel',srcRequest.responseText); if (arguments.length==2) {// alert('A second value is given. We know the model: '+arguments[1]); document.getElementById('selModel').selectedIndex = getValueIndex('selModel',arguments[1]); } }
If the function is supplied a second argument, the selectedIndex is looked up using the getValueIndex() function and set. However, if an alert is fired before (commented out in the above function) the appropriate value does get set. Is the browser not ready poulating the list, so the value cannot be looked up yet? If so, howcome the selectedIndex code is excuted? I really wouldn't like to work with a timer that sets the value half a second or so after the list is populated!If I understood what's going wrong I could find a solution. (BTW: working on IE5.5 -> company browser, in the near future upgraded to IE6).Anyone?