Quantcast
Channel: DaniWeb Solved Topics
Viewing all articles
Browse latest Browse all 564

Show selected option id

$
0
0

Hi DW, I'm trying to get selected option id, the problem with my code is that it is only showing or returning the id of the first select only even if I click other options it doesn't return them.
Heres my code

var xid = $('#managsel option:selected').attr('id');
alert("The id is: " + xid);

Here is my select option code NB: The code is generated by php.

<select class="form-control select2" style="width: 100%;" id="managsel">
<option selected="selected">Select Department</option>
<option id="opa">Accountant</option>
<option id="opb">Training</option>
<option id="opc">Operations</option>
<option id="opd">IT</option>
</select>

Also note that the options id are generated dynamically and I don't know them beforehand.
Thank you.


Viewing all articles
Browse latest Browse all 564

Trending Articles