Reputation: 5790
By default I have set value of drop down to 1.But when I want to retrieve that value in click event I get error. Value of that item I get it as "undefined"
$("#cmbTicketType option[value='1']").prop("selected", true);
I tried this
var sTicketType = $('#cmbTicketType').val();
alert(sTicketType );
HTML:
<select id="cmbTicketType" name="cmbTicketType" multiple="multiple" style="display: none; ">
<option value="1">FLM</option>
<option value="7">Bank</option>
<option value="5">Electrical</option>
<option value="3">Network</option>
<option value="6">Power Failure</option>
<option value="2">SLM</option>
<option value="8">Suspect</option>
<option value="4">UPS</option>
</select>
Upvotes: 2
Views: 1589
Reputation: 10417
Question little unclear. Assuming #cmbTicketType
is the id of select tag, you ccan get value by
var sTicketType = $('#cmbTicketType option:selected').val();
Upvotes: -1
Reputation: 47956
You can set the "selected" value of a <select>
element the same way you extract it's selected value.
To set the value -
$("#cmbTicketType").val(1);
Then you can retrieve the value the same way you are doing now -
var sTicketType = $("#cmbTicketType").val();
Upvotes: 4