Looping through select fields and getting the selected text using jQuery
I spent a little time wrestling with this and I thought it may come in useful to pop on to the blog. In my situation I had to loop through a number of select items as I needed to post some data. I needed to do this as I had to pass 3 sets of information from each select / drop down box. It had to be done this way because I was using the dropdown boxes for a number of different functions, some needed to pull the text and some needed to pull the value.
- The name of the select box
- The value of the select box
- The text of the selected item
$('select').each(function(){
var selected_text = $(this).children('option:selected').text();
})
Happy programming :)var selected_text = $(this).children('option:selected').text();
})
Labels: JavaScript, jQuery, programming
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home