tags:

views:

30

answers:

1

Hi, the following code gives me an alert with the selected value on page load

var itemLevel = $('Select[title=Item Level] option:selected').text();
alert(itemLevel);

But how do I do it if the user selects another value in the dropdown list and I want a new pop up with that value instead?

Thanks in advance.

A: 

Try this:

var itemLevel = $('select[title="Item Level"] option:selected').val();

Or based on name:

var itemLevel = $('select[name*="DropDownChoice"] option:selected').val();

The *= means get select box in whose name there is DropDownChoice somewhere.

If you want to get the text of selected option instead, use text() instead of val() eg:

var itemLevel = $('select[name*="DropDownChoice"] option:selected').text();

Update:

You can do like this:

$('Select[title="Item Level"'].change(function(){
  alert($('option:selected', $(this)).text());
});
Sarfraz
Sorry Sarfraz I just updated the question.
Peter