Getting Select List Values & Text with jQuery

Sep 12

Many time we programmers want to retrieve the value of combo box (select element) with the help of jQuery. Getting the value is very straight forward and simple. It can be done by using [important] val() [/important]. for example.

 

if your select element’s id is “selectbox1” then you can write down :

[important]jQuery("#selectbox1").val();[/important]

 

But if you want to retrieve the value of selected text then you have to perform following :

 

[important] jQuery("#selectbox1 :selected").text() [/important]

 

by using this method you can get the text of selected option in (select element) combo box.

Related Posts:

  • No Related Posts

One comment

  1. Be careful jQuery("#selectbox1 :selected").text() and jQuery("#selectbox1:selected").text() are two different things i wasted lots of time in writing down wrong syntex.

Leave a Reply