'How to check if a specific option was selected from a group of selects
I have a table built with "n" number of rows. On each row I have a select list with the same options. I need to check using jQuery if any of those selects has a particular option selected. For example, I need to know if any of the followings is selected with the value 2.:
<div class="row">
<div class="col">
<select class="fee-type" name="fee-type-options">
<option value="0">*Select</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>
</div>
<div class="row">
<div class="col">
<select class="fee-type" name="fee-type-options">
<option selected="selected" value="0">*Select</option>
<option value="1">Option 1</option>
<option value="2" selected="selected">Option 2</option>
</select>
</div>
...
I tried many things like the following, but in this case I just get the value of the first item select:
$('input[name="fee-type-options option:selected"]').val()
Solution 1:[1]
Try this
$("select").on('change', function () {
$("select").val(); // will return selected value
})
i hope it was useful :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joukhar |
