tags:

views:

28

answers:

3

I'm trying to get the text value of the select option here and i keep getting the value what am i doing wrong here is the code

 jQuery.each(jQuery('select.personalize_toggle'),function(i){
    var t = jQuery(this).html();
    alert(t);
 });

here is the html

 <select class=" personalize_toggle " >
    <option value="0" ></option>
    <option value="1" >Vargas</option>
 </select>

I want to get 'Vergas' out the select in my jquery each loop

Another try

  jQuery.each(jQuery('select.personalize_toggle option:selected'),function(i){
    var val = jQuery(this).text();
    alert(val); // also alerts 1
 });
+2  A: 

You can get it like this:

alert($('#selectbox_id option:selected').text());

Where selectbox_id is the id of the <select> element. If you want to get the value of option, use val() instead of text().

Sarfraz
so i my instance i would want alert($(this + ' option:selected').text()); ???
mcgrailm
A: 
jQuery('select.personalize_toggle') 

returns each select element from your question you seem to want the html inside the option tags i.e. "Vargas" in this case you should change your selector to

jQuery('select.personalize_toggle option')

This will return each option value and alert the contents.

Obsidian
@Obsidian close I don't want all the option values just the selected one
mcgrailm
and thank you too sir
mcgrailm
Ah sorry you didn't realised use the one you selected as an answer with the text() method.
Obsidian
A: 

In the jQuery code you have select.personalize_toggle but you have spelled it differently in html: class=" personalize_toogle ". So correct the spelling, and use .text() to get the text of the option (as pointed by Sarfraz).

Majid
my bad it is correct but still it doesn't work
mcgrailm
thanks for the help
mcgrailm