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.
Try this jQuery,
or this javascript,
If you need to access the value and not the text then try using
val()
method instead oftext()
.Check out the below fiddle links.
Demo1 | Demo2
Use the method below to get the selected value on page load:
For selected text use:
For selected value use:
You need to put like this.
this will do the trick