0

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.

0

4 Answers 4

1

Just use .val(). Try below,

var employee= $('#emplist').val();
Sign up to request clarification or add additional context in comments.

Comments

1

To get the currently selected text:

$('#emplist :selected').text();

Or value:

var value = $('#emplist').val()

Comments

1

You can do

var employee= $('#emplist').find('option:selected').val();

Or the better way

var employee= $('#emplist').val();

Comments

0

Try this

var employee= $('#emplist').val()

      OR

var employee= $('#emplist').find('option:selected').val();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.