1

I have two select dropdown with same classname, I will like to return the title when option value is selected. however with the code I have, when a second dropdown is changed, it still returns the value selected in first option dropdown

http://jsfiddle.net/kgrg/ETeZe/3/

0

3 Answers 3

2

The code you're using to pull out the value:

size_title=jQuery('.child_Select_Size  option:selected').attr("title");

Is matching all .child_Select_Size elements. To limit to just the one which triggered the event, try:

size_title=jQuery('option:selected', this).attr("title");
Sign up to request clarification or add additional context in comments.

Comments

0

Because inside the change handler jQuery('.child_Select_Size option:selected') will select both the elements selected option and calling attr('title') on these matched elements will always give the title of the first element.

You should make use of this keyword which points to the element which raised the event. $(this).find will only look inside the element which raised the event. Also make use $ instead of jQuery if there is no conflict or use jQuery.noConflict()

$('.child_Select_Size').change(function(elmt){
    alert($(this).find('option:selected').attr("title"));
});

Demo

Comments

0

You just need to use $(this) to refer to the select box that has changed, instead of just using a new selection (which will grab all).

http://jsfiddle.net/ETeZe/10/

1 Comment

Also there was some un-needed complexity in your script that I stripped out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.