This has been bothering me all day, if anyone can help I would be greatful.
if(aaid) {
var num_one = aaid;
var radioBox = document.getElementsByName('used_dealer_before');
for (i = 0; i < radioBox.length; i++) {
if(num_one) {
radioBox[i].checked = true; //this auto checks the box
}
}
radioBox.onchange=function(){
document.getElementById("previous_dealer").value=num_one; //this auto selects the value from the dropdown
}
}
The function above auto checks a radiobox if a variable (aaid) is present, once this box is checked there is another function in another script file (to which I do not have access; long story) that presents a dropdown menu. The next part of MY script auto-selects a value on the dropdown. This script works and has been tested locally. However, when I upload it to the server it does not execute the 2nd part of the script anymore. I suspect because the function already executes, when the page hasn't finished rendering the dropdown value. Therefore, can anyone explain to me how to use JavaScript to wait for the dropdown to appear, before it continues with the script?
Should I time delay the function? I cannot use jQuery, I have to use JavaScript.
radioBox.length> 0. on page where you have the problem?radioBox.onchange = ...does not make sense becausradioBoxis an array.document.createElement('script')?