Share on Google+Share on Google+

lavanya satyavarapu
this is my javascript code to display all errors in one single alert box, but i am not getting this,please help me to sort out this?
0 Answer(s)      4 years and 5 months ago
Posted in : JavaScript Questions
<html>
    <script language = "JavaScript">
function checkName(text) {
if(isNaN(text)){ return 1;}
else{alert("Please enter a valid name. The only charachters accepted are A - Z and a - z");return 0;}
}
function checkAddress(text) {
if(isNaN(text)){ return 1;}
else{alert("Please enter a valid address. The only charachters accepted are A - Z and a - z");return 0;}
}


function validate(){
   var Errortext="";

    var emailID=document.form.email;
        var nn1=document.form.fname;
        var nn2=document.form.lname;
        var add=document.form.address;
        var gen=document.form.radios;
        var mobile=document.form.mobilenumber;
        var city=document.form.cityname;
        var state=document.form.statename;
        var zip=document.form.zip1;
        var password=document.form.pass;
        var cpassword=document.form.cpass;

      if(nn1.value == ""){
      Errortext+="Please enter first name\n";

    nn1.focus();
    return false;
      }
     else if (checkName(nn1.value)==false){
      nn1.value=""
      nn1.focus()
      return false
      }

      else if (nn2.value == ""){
      Errortext+="please enter your name\n";

    nn2.focus();
    return false;
      }
      if (checkName(nn2.value)==false){
      nn2.value=""
      nn2.focus()
      return false
      }
       else if ( (gen[0].checked == false ) && ( gen[1].checked == false ) ){
    Errortext+="please check your gender: Female or Male\n";
    gen[0].focus();
    return false;
    }
      else if ((emailID.value == "" ||emailID.value.indexOf('@', 0) == -1) ||emailID.value.indexOf('.') == -1){
      Errortext+="please enter proper email id\n";
      emailID.focus();
      return false;
      }
    else if(mobile.value=="")
    {
    Errortext+="please Enter the Contact Number\n";
    mobile.focus();
    return false;
    }
    else if(isNaN(mobile.value)||(mobile.value.length!=10))
    {
    Errortext+="Enter the valid Mobile Number\n";
    mobile.focus()
    return false
    }


      if(password.value==""){
     Errortext+="password should be filled\n";
      password.focus();
      return false;
      }
      if(cpassword.value==""){
      Errortext+="confirm password should be filled\n";
      cpassword.focus()
      return false
      }
      if((cpassword.value=="")||(password.value!=cpassword.value)){

    Errortext+="Please enter Password and confirm password and both should be same\n";
     cpassword.focus()
      return false

  }

  if (add.value == ""){
    Errortext+="Please enter address\n"; 
    add.focus();
    return false;
    }
    if (checkAddress(document.form.address.value)==false){
      address.value=""
      address.focus()
      return false
      }
  if(city.value==""){
      Errortext+="please enter your city\n";
      city.focus();
      return false;
  }    
  if(state.value==""){
      Errortext+="please enter your state\n";

      state.focus();
      return false;
  }   
  if( zip.value == "" || isNaN(zip.value ) ||zip.value.length != 6 ){
        Errortext+= "Please provide a zip in the format ######.\n";
        zip.focus();
        return false;
        }
   if(Errortext!=""){
       alert( Errortext) 
    return false; 
   }


    return true

}
    </script>
    <form name="form"  onSubmit="return validate()">
        <pre>
    First Name<input type="text" name="fname" id="fn" size="30">
    Last Name<input type="text" name="lname" id="ln" size="30">
    Gender<input type="radio" name="radios" value="male">Male <input type="radio" name="radios" value="Female">Female
    Enter an Email Address<input type="text" name="email" size="30">
    Mobile Number<input type="text" name="mobilenumber">
    Password<input type="password" name="pass">
    Confirm Password<input type="password" name="cpass">
    Address1<input type="text" name="address">
    Address2<input type="text" name="add2">
    Address3<input type="text" name="add3">
    City<input type="text" name="cityname">
    State<input type="text" name="statename">
    ZIP<input type="text" name="zip1">
    <input type="submit" name="Submit" value="Submit">
        </pre></form>

</html>

Ads

View Answers









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads