Hi folks, I have a script that dynamically adds options to a select box. The items are just numbers. I have a for loop that uses a value from another control as a starting point and yet another var to match on to show witch item s/b "selected". When the page is loaded the function gets called and the selected item is always one less than it s/b. I put an alert in the funtion to display the vars and when the page is loaded and after the alert shows the vars, the drop down has the correct value! I take the alert out and it is wrong again! That makes debugging quite a challenge. Here is the function ... if I put an alert anywhere in there the correct item gets selected ... otherwise the item seleted is one less than it should be ...
function updateDay2_2()
{
var x2=document.getElementById("theSecondDay")
var y2=x2.value
var x=document.getElementById("dayTwo")
var selectIndex = document.getElementById("dayOne").selectedIndex
numOptions = x.options.length
for (i=0;i<numOptions;i++)
{
x.remove(x.i)
}
if (selectIndex > 0 ¦¦ selectIndex == 1)
{
selectIndex = selectIndex + 1
}
if (selectIndex == 0)
{
selectIndex = 1
}
for (i=selectIndex;i<28;i++)
{
var y=document.createElement('option');
y.text=i+1
if ( y.text == y2 )
{
y.selected='true'
}
x.add(y)
}
}