Retrieving HTML select values with jQuery
Snippet
Written with a loving hand by kitt some time around 15:37 on 11 August 2009
Ways to select the various option values from a select list, using jQuery.
/* <select name="payment" id="selectList"> <option value="1">Visa</option> <option value="2">Mastercard</option> <option value="3">American Express</option> <option value="4">JCB</option> </select> */ $('#selectList').val(); // returns value of options 1, 2, 3, or 4 $('#selectList :selected').text() // returns text of options Visa, Mastercard, if selected // multiple select: var sel = []; $('#multiple :selected').each(function(i, selected) { sel[i] = $(selected).text(); });
Add new comment