I'm trying to remote validate a field by looking at two different fields. The issue is, in all the examples I see on how to do remote validate sending additional data, they're using the id of the other field that is being processed. So the example on the jQuery validate API page for remote() uses "#username" and sends that in addition to the email field.
My page is odd, and has multiple forms that are the same, and the number of forms on the page is variable, so I can't have a unique id for each field. Is there a way to find out which field or form is being validated/making the remote call? I tried something like the following, because I thought that $(this) would have been the text box being validated, or the individual form being validated, but that doesn't appear to be the case.
number: {
required: true,
number: true,
remote: {
url: "confirm.php",
data: {
toy: function() {
return $('select[name="toy"]:selected',this).val();
}
}
}
}
Thanks, Jared
Edit: I ended up figuring out a way to get it working. The advice to pass the form along gave me the idea.
Since I had multiple forms on the page, I was using $('form').each(function() {$(this).validate({....})});
So I just saved a reference to the current form with var form = $(this) before the validate call, and then within the example I gave earlier I only had to make a small change:
data: {
toy: function() {
return $('select[name="toy"]',form).val();
}
}
And now each field knows which form it belongs to!