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!

How to get SELECT value with getElementById

Status
Not open for further replies.

robulator

Programmer
Nov 17, 2000
33
US
I'm trying to extract the selected value from a SELECT element using getElementById() so that it will be compatible with IE and NS 6. It works fine in NS 6, but not in IE 5.5. No value is returned in IE. Does anyone know if it can be made to work in both browsers? By the way, getElementsByTagName doesn't work in IE with the SELECT element either.

Thanks for help

Robopino
 
Perhaps you could give some sample code. I think some browsers allow selectObj.value, whereas others need selectObj.options[ selectObj.selectedIndex ].value.

Cheers, NEIL
 
Here's some code:
<HTML>
<BODY>

<SCRIPT>
function ShowWell() {
alert(document.getElementById(&quot;Location&quot;).NSSelect.value)
}
</SCRIPT>

<FORM NAME=&quot;Location&quot; ID=&quot;Location&quot;>
<SELECT ID=&quot;NSSelect&quot; NAME=&quot;NSSelect&quot; SIZE=1>
<OPTION SELECTED> NORTH
<OPTION> SOUTH
</SELECT><BR>

<INPUT TYPE=&quot;BUTTON&quot; VALUE=&quot;Select&quot; onclick=&quot;ShowWell()&quot;>
</FORM>
</BODY>
</HTML>


As a variation you can try document.getElementById(&quot;NSSelect&quot;).value, but neither work in IE.

 
OK. I've got it. In IE you must define the VALUE attribute in the SELECT tag, but this is not necessary in NS6.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top