views:

53

answers:

2

Hey guys,

Probably a simple one, but I need some help. I had some radio buttons and was using the following jQuery to see which was checked:

var desc1 = ($('input[name=area]:checked').val());

That worked fine, but I now need to use a drop down menu instead of the radio buttons. I tried the same jQuery and also with "selected" instead of "checked" but no luck. How do I get this to work?

Thanks

+3  A: 

What you're trying to get is in fact the value of the <select> element:

$("select").val();
You
works perfect, will accept as answer in 2 mins, thanks
IceDragon
A: 

The select is just a single element, the option tags doesn't end up as elements themselves.

Just use the val method to get the value of the selected option:

var desc1 = $('select[name=area]').val();
Guffa
hmm that doesnt seem to display anything (when i call desc1 as i did before that is)? thanks
IceDragon
@Icedragon: Right, it's a select tag, not an input tag. Corrected.
Guffa