Amit Amit - 1 year ago 72
jQuery Question

Get selected key/value of a combo box using jQuery

Please, how can I get the selected key and value of a HTML select 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?


Answer Source

I assume by "key" and "value" you mean:

    <option value="KEY">VALUE</option>

If that's the case, this will get you the "VALUE":


And you can get the "KEY" like this: