Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option.value in Netscape 4.x

Status
Not open for further replies.

Bakunin

Programmer
Dec 21, 2000
31
GB
Hi,
can anyone tell me if netscape 4.x knows about the options.value property? Basically I have a dropdown box populated from the database, with the value set to an ID and another field displayed to the user.

Based on as selection I want to grab the ID which is set as each option value attribute and pass it to a function which will select the same Id in another drop down with the same ID.

This work in IE5.x, Netscape 6.x, but not Netscape 4.7. Does anyone know a workaround?

Code to highlight below



<html>


<SCRIPT LANGUAGE = &quot;JavaScript&quot;>
<!--

function XXX() {

alert(document.form1.cars.options[document.form1.cars.selectedIndex].value);

document.form1.cars.options.value = 2;
}

// -->

</SCRIPT>

<form name=&quot;form1&quot;>

<body>


<select name=&quot;cars&quot;>
<option value=&quot;1&quot;>Volvo</option>
<option value=&quot;2&quot;>Saab</option>
<option value=&quot;3&quot;>Fiat</option>
<option value=&quot;4&quot;>Audi</option>
</select>

<input type='button' value='Run' onClick='XXX();'>


</body>

</form>


</html>

 
hie
try to move form inside of the body section, & it will do the job (nn4.61 under win98) Victor
 
Many thanks Victor.

Is it possible to set the chosen item in the list based on its value.

So for example

<select name=&quot;cars&quot;>
<option value=&quot;5&quot;>Volvo</option>
<option value=&quot;2&quot;>Saab</option>
<option value=&quot;3&quot;>Fiat</option>
<option value=&quot;10&quot;>Audi</option>
</select>

I want to select &quot;Audi&quot; as the selected index based on its value. In IE5.x this is

document.form1.cars.options.value = 2;

but doesn't work in Netscape 4.x
Thanks in advance.

Tony.
 
here u go:
<html>
<SCRIPT LANGUAGE = &quot;JavaScript&quot;>
<!--
function XXX() {
alert(document.form1.cars.options[document.form1.cars.selectedIndex].value);

document.form1.cars.selectedIndex = 2;
//note that index begins with 0 so, 2 wuld be Fiat in this case..
}
// -->
</SCRIPT>
<body>
<form name=&quot;form1&quot;>
<select name=&quot;cars&quot;>
<option value=&quot;1&quot;>Volvo</option>
<option value=&quot;2&quot;>Saab</option>
<option value=&quot;3&quot;>Fiat</option>
<option value=&quot;4&quot;>Audi</option>
</select>
<input type='button' value='Run' onClick='XXX();'>
</form>
</body>
</html>

right syntax of what u was trying to do:

document.form1.cars.options[document.form1.cars.selectedIndex].value=2 (as single line)

but

doing it just like this will just set selected item's value 2 whatever u will assign (2 in ur case) so, u have to set selectedIndex 2 whatever u want

hope that was clear..
Victor
 
Yes Victor, I thought that was the case.

Again thanks for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top