How can I get the selected value of a dropdown box using jQuery?
I tried using
var value = $('#dropDownId').val();
and
var value = $('select#dropDownId option:selected').val();
but both return an empty string.
How can I get the selected value of a dropdown box using jQuery?
I tried using
var value = $('#dropDownId').val();
and
var value = $('select#dropDownId option:selected').val();
but both return an empty string.
I know this is a terribly old post and I should probably be flogged for this pitiful resurrection, but I thought I would share a couple of VERY helpful little JS snippets that I use throughout every application in my arsenal...
If typing out:
is getting old, try adding these little crumpets to your global
*.js
file:and just write
soval("#selector");
orsotext("#selector");
instead! Get even fancier by combining the two and returning an object containing both thevalue
and thetext
!It saves me a ton of precious time, especially on form-heavy applications!
The
id
that got generated for your drop down control in thehtml
will be dynamic one. So use the complete id$('ct100_<Your control id>').val().
It will work.use either of these codes
OR
use
This should work :)
You can do this by using following code.
If you want to get the selected value from the select list`s options. This will do the trick.