javascript - Not able to call a jquery function in a ajax returned code -


i not of javascript programmer, learning please forgive stupid mistakes.

i trying save customer details using ajax (its not jquery ajax), returns form advanced details. using jquery plugin validation of input boxes. validation doesn't work on form returned ajax.

ajax code:

function createcustomer() {     var firstname = _("firstname").value;     var lastname = _("lastname").value;     var email = _("email").value;     var phone = _("phone").value;     var status = _("status");     if (firstname == "" || lastname == "" || email == "" || phone == "") {         status.innerhtml = "fill out of form data";     } else {         _("signupbtn").style.display = "none";         status.innerhtml = 'please wait ...';         var ajax = ajaxobj("post", "save-customer.php");         ajax.onreadystatechange = function () {             if (ajaxreturn(ajax) == true) {                  if (ajax.responsetext != "failure") {                     _("signupform").innerhtml = "";                      _("advancedform").innerhtml = ajax.responsetext;                   } else {                     window.scrollto(0, 0);                     _("signupform").innerhtml = "error occured";                 }             }         }         ajax.send("firstname=" + firstname + "&lastname=" + lastname + "&email=" + email + "&phone=" + phone);     }  }  function ajaxobj(meth, url) {     var x = new xmlhttprequest();     x.open(meth, url, true);     x.setrequestheader("content-type", "application/x-www-form-urlencoded");     return x; }  function ajaxreturn(x) {     if (x.readystate == 4 && x.status == 200) {         return true;     } } 

i have tested ajax return code thouroughly , jquery works independently on form. how initiate jquery validation plugin :

$(document).ready(function()    {     $('form').validationengine(); }); 

i tried putting exact code in createcustomer() function reload jquery function doesnt work. there way can call jquery validation function in ajax function? appreciated.

regards priyanshu

i'm suspecting validation trying find form doesnt exists @ execution time, try putting validation binding when have sure form exists in dom. achieve should put validation binder:

$('form').validationengine(); 

...inside callback after ajax loads html data in document. this:

ajax.onreadystatechange = function() {     if(ajaxreturn(ajax) == true) {          if(ajax.responsetext != "failure"){             _("signupform").innerhtml = "";              _("advancedform").innerhtml = ajax.responsetext;             $('#ajaxreturnform').validationengine('attach'); //here          } else {             window.scrollto(0,0);             _("signupform").innerhtml = "error occured";         }     } } 

i've looked around here , found post attach validation accepted answer may inlight problem also. try put 'attach' command parameter binder #id of form.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -