How to get the value of option select box in jQuery if I have the code like this,
<select id='media' name='media'>
<option value='1'>media1</option>
<option value='2'>media2</option>
<option value='3'>media3</option>
</select>
When I code for on change event,
$(document).ready(function()
{
$("#media").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
alert(id); return false;
});
});
It gives me media1
,media2
,media3
instead of 1, 2, 3
How to get the value 1, 2, 3?
$('#media').change(function(){
alert($(this).val());
});
this should work the way you want it should.
$("#id option:selected").val();
Here id
is the id of a select box. I'm sure it will work 100%.
If you want selected text use this one:
$("#id option:selected").text();
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