views:

17

answers:

1

Hey guys. I am trying to get the selected option in an each loop. What is the correct syntax to achieve that?

I tried the following:

var row = $('#template_23423);

row.find('select[name^=COUNTY]').each(function (){
    var selectedOption = $(this).children(':selected').val();

Any ideas?

+1  A: 
var row = $('#template_23423');

row.find('select[name^=COUNTY]').each(function(){
  var selectedOption = $('option:selected', $(this)).val();
};

That will give you the value of the options if you want to their text, use text() instead of val().

Sarfraz
thank you very much! any books you can recommend on jQuery/JS?
Kel
@Kel: I personally love **Learning jQuery**, more details here: https://www.packtpub.com/jQuery/book. And guess what I have learned most of it through stackoverflow :)
Sarfraz
thanks. I am kind of new in jQuery and appreciate everything I can get about it. Thanks again.
Kel
@Kel: You are welcome :) Note that if you search on google **Learning jQuery pdf** you will be able to get its free pdf version for download.
Sarfraz