I have a strange problem where my call to document.getElementById() does not work unless I put alter("whatever"); above the getElementById line.
Description: This is on an ecommerce website which uses JavaScript to change the products listed/add to basket (it is pretty nasty but I must make do).
So, when the user is selecting their shipping method via a <select></select> control I have a onchange handler which calls SetChosenCarriage.
Here is the function:
In the above chosenCarriage is assigned to the chosen select value in a different function (there are 2 functions called onchange).Code:function setChosenCarriage(elem) { var dhlPos = chosenCarriage.indexOf('DHL '); if(dhlPos >= 0) { alert(elem.id); // Need this line document.getElementById(elem.id).selectedIndex = document.getElementById(elem.id).selectedIndex + 1; } }
If I remove the alert line my script crashes and burns but with it the selectedIndex jumps to the second (1) which is the DHL shipping method.
For obvious reasons I do not want the alert to show.
Any idea?