
Untitled
By: a guest on
Jun 21st, 2012 | syntax:
None | size: 0.74 KB | hits: 14 | expires: Never
Get selected key/value of a combo box using jQuery
$(this).find("select").each(function () {
if ($.trim($(this).val()) != '') {
searchString += $.trim($(this).val()) + " "; //This gives me the key. How can I get the value also?
}
});
<select>
<option value="KEY">VALUE</option>
</select>
$(this).find('option:selected').text();
$(this).find("select").each(function () {
$(this).find('option:selected').text();
});
<select name="foo" id="foo">
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>
<input type="button" id="button" value="Button" />
$('#button').click(function() {
alert($('#foo option:selected').text());
alert($('#foo option:selected').val());
});