Sending additional information with JQuery remote form validation -


i'm trying remote validate field looking @ 2 different fields. issue is, in examples see on how remote validate sending additional data, they're using id of other field being processed. example on jquery validate api page remote() uses "#username" , sends in addition email field.

my page odd, , has multiple forms same, , number of forms on page variable, can't have unique id each field. there way find out field or form being validated/making remote call? tried following, because thought $(this) have been text box being validated, or individual form being validated, doesn't appear case.

number: {                   required: true,                   number: true,                   remote: {                     url: "confirm.php",                     data: {                         toy: function() {                             return $('select[name="toy"]:selected',this).val();                         }                     }                   }           } 

thanks, jared

edit: ended figuring out way working. advice pass form along gave me idea.

since had multiple forms on page, using $('form').each(function() {$(this).validate({....})});

so saved reference current form var form = $(this) before validate call, , within example gave earlier had make small change:

data: {     toy: function() {         return $('select[name="toy"]',form).val();     } } 

and each field knows form belongs to!

you assign unique formid each of forms, , whenever form submitted, submit formid alongwith other info form in order identify form being submitted?

for example, in html code of form, this:

form # 1: (with form id 1)

<form id="form_1"> name: <input type='text' id='name_1'> <br> address: <input type='text' id='address_1'> <br>  <input type='button' value='submit' onclick='validate(1);'> </form> 

form # 2: (with form id 2)

<form id="form_2"> name: <input type='text' id='name_2'> <br> address: <input type='text' id='address_2'> <br>  <input type='button' value='submit' onclick='validate(2);'> </form> 

in javascript, this:

function validate(formid) {    var data = {};    //example data submitted validation:    data.name = $("#name_" + formid).val();    data.address = $("#address_" + formid).val();    //.. , on    data.formid = formid;     $.post('http://example.com/confirm.php', data, function(result)      {        //process return of remote validation here,         //found in variable: result      }    ); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -