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
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
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,
Thanks, but that does not seem to make any difference. Also, the name
must be enough because I've got HTML such as input type=hidden
name=txtProjectHomeLink_0 size=30 value=a dummy value
class=ProjectHomeLink_0 / with JQuery x=$
(input.ProjectHomeLink_0).val(); and it gets the value successfully.
The val() method returns the selected option for the element:
$('[name=dllViewSelector]').val()
'selectedIndex' is a property of the select 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
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 ricardob...@gmail.com wrote:
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 i...@legalanalytics.co.uk 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=
7 matches
Mail list logo