0

when I take value from dress, but jquery display value from shoes, what jquery selector for solve my problem? before i use code :

$(document).delegate(".product", "submit", function(){
    alert($(".name").val());
    return false;
});
1
  • 2
    Can you add the HTML? shoes and dresses are what? classes? Commented Sep 30, 2013 at 12:59

2 Answers 2

1

The problem is that .name is a class selector and will find multiple instances. Then when you call .val() it will get the first instance value only. You need to be more specific, I would suggest making use of this (which will be the form) and then finding the .name element within that form (which looks like it will be a unique combination). Something like this:

$(document).delegate(".product", "submit", function(){
    var $form = $(this);//get the current form being submitted
    var $name = $form.find(".name");//find the name element relative to the form
    alert($name.val());//alert the correct relative name value
    return false;
});

Here is a working example


NOTE: delegate has been superseded by the on method as of JQuery 1.7. Which you would use like so:

$(".product").on("submit", function(){
   //code
}

Here is an example of this

Sign up to request clarification or add additional context in comments.

Comments

0

try this:

$(document).delegate(".product", "submit", function(){
    alert($(this).find('.name').val());
    return false;
});

Comments

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.