i'm not getting result with jquery form validation -


this html code , below jquery code..my problem in jquery code have 4 if statments , 1 else statment...my code going first 2 if statement , skipping next 2 ifstatements , directly goes last else statement..i have check alert function in each ifstatement , got alert first 2 statements , last elsestatement...can tell solution??? please tell me how can errors of when call $("#errors").html(errormsg); wrote errors if doesn't show on screen please give reply of both questions thanks.

<head> <style> #container{ width:500px; margin: 0 auto; } #errors{ color:red; margin-left:200px; } </style> </head>  <body> <div id="errors"></div> <div id="container">     <form id="validationform">          <label for="email">email</label>         <input name="email" id="email"/>          <label for="phone">telephone</label>         <input name="phone" id="phone"/>          <label for="pass">password</label>         <input name="pass" type="password" id="pass"/>          <label for="cpass">confirm password</label>         <input name="cpass" type="password" id="cpass"/>         <input id="submitbutton" type="submit" value="submit"/>     </form> </div> </body>  <script> var errormsg = ""; $("#validationform").submit(function (event) {     event.preventdefault();      //regular expression started     function isvalidemailaddress(emailaddress) {         var pattern = new regexp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)+(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?$/i);         return pattern.test(emailaddress);     };      if (!isvalidemailaddress($("#email").val())) {         alert("in emails if");         errormsg = "please enter valid email address";      }     if (!$.isnumeric($("#phone").val())) {         alert("in phone if");         errormsg += "<br>" + "please enter numeric phone number";     }      if ($("#pass").val() != $("#cpass").val()) {         alert("in pass if");         errormsg += "<br>" + "both passwords not match";     }      if (errormsg = "") {         alert("now in success if");         alert("success");     }     else {         alert("in last errors if");         $("#errors").html(errormsg);     }  }); </script> 

the code working coded work.
however have small mistakes.
if (errormsg = "") should if (errormsg == ""). single = assigning not comparing.

the code skipping next if statement because entered same passwords in fields.
if enter different passwords if statement execute.

the other if statement skipping because assigning empty string errormsg (you using single =) , returns same value "" empty string, passed if statement, , because "" not number, if statement evaluates false , if statement not executed.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -