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

Problem with Select.Options

Status
Not open for further replies.

joeoz

Programmer
Oct 18, 2001
24
0
0
US
Could someone please show me how to access the value of a select? Here is where I call the function:

<select name=&quot;select1&quot; onChange=&quot;changeTotal(this,this.selectedIndex);&quot;>
<option value&quot;1&quot;>option 1</option>
<option value&quot;2&quot;>option 2</option>
</select>

This is what doesn't work:

function changeTotal(oSelect,nSelectIndex)
{
alert( oSelect.options[nSelectIndex].value );
}

The strange thing is that if I change it to .text at the end it gets the text of the option!

Any help would be greatly appreciated.
 
Hey man,

I think the problem is that you are misssing an = sign when you assign the value. I added it and it worked so try that.

like this:

<select name=&quot;select1&quot; onChange=&quot;changeTotal(this,this.selectedIndex);&quot;>
<option value=&quot;1&quot;>option 1</option>
<option value=&quot;2&quot;>option 2</option>
</select>

<script>

function changeTotal(oSelect,nSelectIndex)
{
alert( oSelect.options[nSelectIndex].value );
}
</script>


Later
 

document.formName.selectName.options[document.formName.selectName.selectedIndex].value

 
Thanks! I'm such an idiot. I knew it should work. I've done plenty of stuff like this before but I just could not figure it out. Sometimes it's the simple things we overlook.

Everything is right with the world again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top