tags:

views:

158

answers:

3

My dropdownlist has an ID of ID=ddltest

How can I reference the selected item in the drop down using jquery?

A: 
jQuery("#ddltest").val();
Justin Ethier
its funny I have never used the jQuery keyword, always use the $.
mrblah
Using the `jQuery` name is certainly more portable than assuming `$` will be an alias to `jQuery`. I wonder what percentage of sites use multiple JS frameworks that want to use the `$` alias...
Brandon Belvin
A: 
$('select#ddltest option:selected').each(function(){
 alert($(this).val());
});
Colin
If you're selecting by ID, you don't need to specify the tag. There should only be one element with that ID. e.g. $('#ddtest option:selected')
John Sheehan
ah yes, good point!
Colin
+3  A: 
$("#ddltest").val();

will give you the value of the selected item

If you want the actual selected item itself:

$("#ddltest option:selected");
Brandon Belvin