I have a drop-down which is auto-built by jQuery. It's running fine.
When the user selects a value from the drop-down I would like to know what the value is. Currently I'm using:
var employee= $('#emplist').find('option:selected').text();
but this seems to always return null.
Can someone tell me how to get the drop-down selected text to a variable.
My jQuery version is 1.4.1.
Just use .val()
. Try below,
var employee= $('#emplist').val();
To get the currently selected text :
$('#emplist :selected').text();
Or value :
var value = $('#emplist').val()
You can do
var employee= $('#emplist').find('option:selected').val();
Or the better way
var employee= $('#emplist').val();
Try this
var employee= $('#emplist').val()
OR
var employee= $('#emplist').find('option:selected').val();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.