php - jquery validations are not working when i click on submit button -
i have written html form , jquery perform validations. when click submit button, nothing happening. can't understand going on, whether form linking jquery file or not. please check code , me.
index.html
<html> <head> <title>validation</title> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/custom.js"></script> </head> <body> <form action="" method="post" id="reg_form"> <p>name:</p> <p><input id="name" name="name" type="text"></p> <p>what's name?</p> <p>email:</p> <p><input id="email" name="email" type="text"></p> <p>enter mail id</p> <p>password:</p> <p><input id="pass1" name="pass1" type="password"></p> <p>more 8 characters</p> <p>password:</p> <p><input id="pass2" name="pass2" type="password"></p> <p>same above</p> <p>phone</p> <p><input id="phone" name="phone" type="text"></p> <p>what's number?</p> <input id="submit" name="submit" type="submit" value="submit"/> </form> </body> </html>
custom.js
$(document).ready(function(){ var form = $("#reg_form"); var name = $("#name"); var namedetails = $("#namedetails"); var email = $("#email"); var emaildetails = $("#emaildetails"); var pass1 = $("#pass1"); var pass2 = $("#pass2"); var pass1details = $("#pass1details"); var pass2details = $("#pass2details"); var phone = $("#phone"); var phonedetails = $("#phonedetails"); var button = $("#submit"); name.blur(validatename); email.blur(validateemail); pass1.blur(validatepass1); pass2.blur(validatepass2); phone.blur(validatephone); name.keyup(validatename); email.keyup(validateemail); pass1.keyup(validatepass1); pass2.keyup(validatepass2); phone.keyup(validatephone); form.submit(function(){ if(validatename() & validateemail & validatepass1 & validatepass2() & validatephone()){ return true; }else{ return false; } }); function validatename(){ if(name.val().length<5){ name.addclass("error"); namedetails.text("your name should have atleast 5 characters"); nameinfo.addclass("error"); return false; }else{ name.removeclass("error"); namedetails.text("whats name?"); } } function validateemail(){ var = $("#email").val(); var regexp = /^[a-za-z0-9]+[a-za-z0-9_.-]+[a-za-za-z0-9_-]+@[a-za-z0-9]+[a-za-z0-9.-]+[a-za-z0-9]+.[a-z]{2,4}$/; if(filter.text(a)){ email.removeclass("error"); emaildetails.text("enter mail id"); emaildetails.removeclass("error"); return true; }else{ email.addclass("error"); emaildetails.text("enter valid mail id"); emaildetails.addclass("error"); } } function validatepass1(){ if(pass1.val().length<8){ pass1.addclass("error"); pass1details.text("8 characters or more"); pass1details.addclass("error"); return false; }else{ pass1.removeclass("error"); pass1.details.text("enter mail id"); pass1.details.removeclass("error"); return true; } } function validatepass2(){ if(pass2.val().length < 1){ pass2.addclass("error"); pass2details.text("8 characters or more"); pass2details.addclass("error"); return false; } if(pass1.val()!== pass2.val()){ pass2.addclass("error"); pass2details.text("8 characters or more"); pass2details.addclass("error"); return false; }else{ pass2.removeclass("error"); pass2.details.text("same above"); pass2.details.removeclass("error"); return true; } } function validatephone(){ var b = $("#phone").val(); var regexp = /[0-9]{10}/; if(filter.text(b)){ email.removeclass("error"); emaildetails.text("enter phone number"); emaildetails.removeclass("error"); return true; }else{ email.addclass("error"); emaildetails.text("enter valid phone number"); emaildetails.addclass("error"); } } });
use statements this,
var name = $("#name ").val();
or
var name = jquery("#name ").val();
and try...it work...
Comments
Post a Comment