Hi there guys I want the error i.e "Not Valid Email" of my email to appear infront of EMAIL: by using "onBlur", like in case of password the error of "Password Do not Match" appears infront of Confirm password. can some me tell me what iam doing wrong??
Code:<html> <head> <title>Form</title> <link rel="stylesheet" type="text/css" href="form.css" /> </head> <body> <script> function s_form() { var uname=document.getElementById("uname").value; var pass=document.getElementById("pass").value; var conpass=document.getElementById("conpass").value; var email=document.getElementById("email").value; var fname=document.getElementById("fname").value; var lname=document.getElementById("lname").value; var atpos=email.indexOf("@"); var dotpos=email.lastIndexOf("."); if(uname=="" || pass=="" || email=="" || fname=="" || lname=="") { document.getElementById("imp").innerHTML="You must fill all the * fields"; } } function checkmail() { var x=document.getElementById("pa"); if(atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length) { x.innerHTML="Not Valid Email"; x.style.color="red"; } else { document.write("yea"); } } function checkpass() { var pass_res=document.getElementById("ap"); if (pass=="" || conpass=="") { pass_res.innerHTML="Enter Password"; } else { if (pass != conpass) { pass_res.innerHTML="Password Do not Match"; } else { pass_res.innerHTML="Password Match"; pass_res.style.color="blue"; } } } </script> <form> <h2>Enter Info for Sign UP</h2><br/> <label id="imp">Fill all the * Fields</label><br/><br/> Enter User Name:<input id="uname" type="text" /><b>*</b><br/></div> Enter Password:<input id="pass" type="password"/><b>*</b><br/></div> Confirm Password:<input id="conpass" type="password" onBlur="checkpass();" /><span id="ap"></span><br/> Enter Email:<input id="email" type="text" onBlur="checkmail();"/><label id="pa"></label><br/> Enter First Name:<input id="fname" type="text"/><b>*</b><br/> Enter Last Name:<input id="lname" type="text"/><b>*</b><br/><br/> <input type="button" value="submit" onClick="s_form();"/> </form> </body> </html>


Reply With Quote

Bookmarks