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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Dropdown Value using Netscape?! 2

Status
Not open for further replies.

awol2k

Programmer
Apr 23, 2001
7
US
How can I return the value of a drop down in Netscape? Here is some basic code. In IE the value is show in an alert and is correct. In Netscape it is shown in an alert at null? What am I doing wrong here in regards with returning the dropdown value in Netscape?

<html>
<head>
<title></title>
<script language=&quot;JavaScript&quot;>
function getValue() {
var x;
x = document.form1.select.value;
alert (x);
}
</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
<select name=&quot;select&quot; OnChange=&quot;getValue()&quot;>
<option value=&quot;1&quot;>Number1</option>
<option value=&quot;2&quot;>Number2</option>
</select>
</form>
</body>
</html>

Thanks,

Ed
 
With Netscape you need to retrieve the value of the option object that was selected from the select box. Here's a new version of your function.

Tim

Code:
function getValue() {
    var x;
    
    iSelected = document.form1.select.selectedIndex;
    x = document.form1.select.options[iSelected].value;
    alert (x);
}
 
I know it's long, but use this:

val = document.form1.select.options[document.form1.select.selectedIndex].value
alert (val)



Fengshui_1998
 
also note that :
with :
<option value=&quot;1&quot;>Number1</option>

document.form1.select.options[document.form1.select.selectedIndex].value will return 1
whereas
document.form1.select.options[document.form1.select.selectedIndex].text will return Number1
 
Thanks, is compatible with NN and IE?

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top