Usually I use $("#id").val()
to return the value of the selected option, but this time it doesn't work. The selected tag has the id aioConceptName
html code
<label>Name</label> <input type="text" name="name" /> <select id="aioConceptName"> <option>choose io</option> <option>roma</option> <option>totti</option> </select>
With jQuery, it's easy to get selected text from a drop-down list. This is done using the select id. To change the selected value of a drop-down list, use the val() method.
$('#mySelectBox option'). each(function() { if ($(this). isChecked()) alert('this option is selected'); else alert('this is not'); });
For dropdown options you probably want something like this:
var conceptName = $('#aioConceptName').find(":selected").text();
The reason val()
doesn't do the trick is because clicking an option doesn't change the value of the dropdown--it just adds the :selected
property to the selected option which is a child of the dropdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With