Reputation: 27
I am developing one website, where multiple dropwn list exists as below:
<select name="campaign[nmb][0][trgt_nmb]">
<option value="">Please Select</option>
<option selected="selected" value="1">VAL1</option>
<option value="2">VAL2</option>
<option value="3">VAL3</option>
</select>
<select name="campaign[nmb][1][trgt_nmb]">
<option value="">Please Select</option>
<option selected="selected" value="4">VAL4</option>
<option value="5">VAL5</option>
</select>
The above drop-down list generates dynamically. Due to some requirement, I want a particular "Select" field value by name using Jquery.
i.e the value of campaign[nmb][0][trgt_nmb]
is 1.
Kindly suggest. Thanks in advance.
Upvotes: 1
Views: 846
Reputation: 7491
Try using the name selector and retrieve the selected value by using val()
:
$('select[name="campaign[nmb][0][trgt_nmb]"]').val();
Working example here: http://jsfiddle.net/p7cve/1/
Documentation for using attributes as selectors here: http://api.jquery.com/attribute-equals-selector/
And for getting values of select's here: http://api.jquery.com/val/
Upvotes: 1