ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4 && ajaxRequest.status==200){ var tx2 = ajaxRequest.responseText; var selectedItem = ""; for (i =0; i< listCounter; i++){ selectedItem = "list#" +x; formElmts[selectedItem].innerHTML = tx2; } } } Code (markup): The code is suppose to change multiple drop down lists with the same text is returned from ajaxRequest.responseText. why dont for loops work inside of onreadystatechange? I have been researching and it seems its because its asynchronous. Any tips on how to make it work.
what are listCounter and x values, are u sure that this vars are accessible inside your function? my bet is that u set those vars in wrong place or wrong way and ur function simply doesnt have access to them.
The result was it only edited the first element only. I researched it said something with the queue. I tried it with a while loop instead and it magically worked. Not sure why but it works for now. Any ideas how to fix it or a legit way around it?