[jQuery] Re: Problem getting selected value from drop-down

2009-05-17 Thread Ricardo
Well, .val() on the select element returns the current value, so you can simplify that: $('select#myselect').change(function(){ var itemText = $(this).find('option:selected').text(); var itemValue = $(this).val(); $( '#answer' ).text( itemText + ' is number ' + itemValue ); }); or go even s

[jQuery] Re: Problem getting selected value from drop-down

2009-05-17 Thread cherry.aus...@gmail.com
Can I just thank you guys!! I've wasted hours trying to fiddle around with selectedIndex and stuff; the best I achieved was to get the html object returned :( It wasn't clear from the docs. Confusingly, I did get the option text with $( 'select#myselect option:selected' ).text(). But I couldn't g

[jQuery] Re: Problem getting selected value from drop-down

2009-03-31 Thread Rob
I should have expounded more on the rest of it, but I had to run to a meeting. My apologies. :( On Mar 31, 11:21 am, LinkGuru wrote: > Apologies to Rob (I had only tried his 'add the id attribute to > the select tag' suggestion), I now find that if I write p_viewSelector= > $("select[name='dllVi

[jQuery] Re: Problem getting selected value from drop-down

2009-03-31 Thread LinkGuru
Apologies to Rob (I had only tried his 'add the id attribute to the select tag' suggestion), I now find that if I write p_viewSelector= $("select[name='dllViewSelector'] option:selected").text(); it works fine. Thanks Rob (and also Ricardo). On Mar 31, 3:53 pm, Ricardo wrote: > The val() method

[jQuery] Re: Problem getting selected value from drop-down

2009-03-31 Thread Ricardo
The val() method returns the selected option for the element: $('[name=dllViewSelector]').val() 'selectedIndex' is a property of the node. When you call $ ('#dllViewSelector') (ignoring the fact that this selector is wrong) you get a jQuery object with a reference to the element, not the elemen

[jQuery] Re: Problem getting selected value from drop-down

2009-03-31 Thread LinkGuru
Thanks, but that does not seem to make any difference. Also, the name must be enough because I've got HTML such as with JQuery x=$ ("input.ProjectHomeLink_0").val(); and it gets the value successfully. It's just with the selector I'm having trouble. Note that it is not coming back with undefined,

[jQuery] Re: Problem getting selected value from drop-down

2009-03-31 Thread Rob
One thing I see wrong there: You are referencing dllViewSelector as an id in your jQuery, but you only have that as a name in your html. either add the id attribute to the select tag, or reference it as $("select[name='dllViewSelector'] option:selected") in your jQuery. On Mar 31, 6:51 am, LinkG