javascript_howto thread: Repopulating <select> in javascript not displaying selected value in Netscape
Hi All,
Ok, here's the problem: I am working with 2 dropdown lists, the 1st of
which controls what the 2nd displays. I need this done without refreshing
the page, so I'm using javascript to achieve this. The dropdown refreshes
the data in the 2nd dropdown list based on what is selected in the first
dropdown list just fine. The problem occurs when there is only 1 value in
the second dropdown list.
For the I.E. user, if the 2nd dropdown contains a single value, the field
within the dropdown control displays the value. When the user clicks the
dropdown arrow, the single value is listed below the arrow.
For the Netscape user, if the 2nd dropdown contains a single value, the
field within the dropdown control is blank. When the user clicks the
dropdown arrow, the single value is listed below the arrow. BUT when the
value is selected, the value is NOT displayed when focus leaves the control.
This is the code which populates the 2nd dropdown list when the 1st
dropdown is changed:
numberoftasktypes = tasklistarray.length;
for (var loopcount=0; loopcount<numberoftasktypes; loopcount++)
{
if ( tasklistarray[loopcount][0]==ProjectIndexValue )
{
document.Form1.ddlTaskType.options.length++;
insertindex = document.Form1.ddlTaskType.options.length-1;
document.Form1.ddlTaskType.options[insertindex].text =
tasklistarray[loopcount][2];
document.Form1.ddlTaskType.options[insertindex].value =
tasklistarray[loopcount][1];
}
}
The following code sets the selected item based on an original value:
if (origTaskTypeID > 0)
{
/* Set the original value, prior to filtering the list based on project. */
numberoftasktypes = document.Form1.ddlTaskType.length;
for (var loopcount=0; loopcount<numberoftasktypes; loopcount++)
{
if (document.Form1.ddlTaskType.options[loopcount].value == origTaskTypeID)
{
document.Form1.ddlTaskType.options[loopcount].selected = true;
break;
}
}
}
If anyone can give me a hand in getting the value displayed in the dropdown
control when the focus is changed to another field, this would be very helpful!
Thanks,
Chris