Content feed Comments Feed

The Official ASATO Site

Hi, welcome to my blog. ASP,asp.net,Health,Javascript,JQUERY

How to get value of select box by using javascript

Posted by admin On April - 13 - 2009

options is an array property of the Javascript select object. The options array define the options of the select box with indices starting from zero.

To grab the value* or text** of a option in the select box, you must know it’s index. Most of the time you’ll only need use of the user selected option, so we can use the select object’s selectedIndex property to get the index we want, then use that to get the value of the option we want. This code example will grab the selected value of the myselect select box:

?View Code CSHARP
1
myselect.options[myselect.selectedIndex].value

This is an select box:

?View Code CSHARP
1
2
3
4
5
<select onchange="window.location=this.options[this.selectedIndex].value">
    <option value="#">Select a search engine</option>
    <option value="http://www.google.com">Google</option>
    <option value="http://www.yahoo.com">Yahoo</option>
</select>

One Response to “How to get value of select box by using javascript”

  1. Zoran says:

    Everything dynamic and very positively! :)

Leave a Reply