Hmm.. I'm surprised that IE even lets you do that. At any rate, the
value property is a settable property in JavaScript, it can only be set through the options index. I've yet to see someone try to set a value to the actual select list. But at any rate, as you can see, NS won't parse that script properly.
According to my JS reference, the only way to change the current selection in a select list dynamically is to use the
document.selectlist.options[n].selected = true. This will deselect the current option and select the option indicated by the
options[n] index number.
Now, you're particular need is quite challenging because it's possible that you will not know the options index number that you want to change the list to. In your example above, what you want to give JavaScript is the
value and you want JavaScript to select the option in the list that contains that value.
To do this, you're going to have to tell JavaScript to loop through every option in the list until it finds the value you're looking for, then select that option.
I've created a
ready to run sample page that shows you exactly how this is done. Now, I tried to copy as much of your convention and element names into this example, but of course, I am not referencing an
opener window and I am not using a date object to set the search value. Nonetheless, you should be able to see here how it's done.
There's a small onLoad event handler function that sets the Text in the button just for the purpose of this test. You can ignore that as part of your solution.
Basically, change the value of the
var d = "n" setting. Reload the browser and click on the button. You'll see JavaScript will dynamically set the list in code.
Works in both IE and Netscape
Code:
<html>
<head>
<script Language="JavaScript">
<!--
var d = "4"
function changeList() {
for (var m = 0; m < document.UpdateSuburb.dayStarted.length; m++) {
if (document.UpdateSuburb.dayStarted.options[m].value == d) {
document.UpdateSuburb.dayStarted.options[m].selected = true
}
}
}
function setButtonText() {
document.UpdateSuburb.change.value = "Change List To " + d
}
//-->
</script>
</head>
<body onLoad="setButtonText();">
<form name="UpdateSuburb">
<select name="dayStarted">
<option value="1">1 </option>
<option value="2">2 </option>
<option value="3">3 </option>
<option value="4">4 </option>
<option value="5">5 </option>
<option value="6">6 </option>
</select><br><br>
<input name="change" type="button" value="" onClick="changeList()">
</form>
</body>
</html>
Hope this helps
Let me know if you get hung up or have any questions.
ToddWW