469,934 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Java Script Validation failed in Mozila and IE but work in Chrome & Safari

semanticnotion
I have problem with this code. it work in chrome and safari but in Mozila and IE when i clicked the submit button without filling the fields it will submit the form and move to other page.

Expand|Select|Wrap|Line Numbers
  1. function validateFormOnSubmit() {
  2.     var checkEmpty = new Boolean(false);
  3.     checkEmpty  = this.IsEmpty(ssn);
  4.     //checkEmpty  = this.IsEmpty(dob);
  5.     checkEmpty  = this.IsEmpty(lname);
  6.     checkEmpty  = this.IsEmpty(fname);
  7.     checkEmpty  = this.IsEmpty(middle_initial);
  8.     checkEmpty  = this.IsEmpty(spouse_lname);
  9.     checkEmpty  = this.IsEmpty(spouse_fname);
  10.     checkEmpty  = this.IsEmpty(spouse_middle_initial);
  11.     checkEmpty  = this.IsEmpty(street_no);
  12.     checkEmpty  = this.IsEmpty(address);
  13.     checkEmpty  = this.IsEmpty(city);
  14.     checkEmpty  = this.IsEmpty(zip);
  15.     checkEmpty  = this.IsEmpty(cell);
  16.     checkEmpty  = this.IsEmpty(business_phone);
  17.     checkEmpty  = this.IsEmpty(extention);
  18.     checkEmpty  = this.IsEmpty(home_phone);
  19.         if (checkEmpty == false){
  20.             alert("alert");
  21.  
  22.             return false
  23.         }
  24.  
  25.  
  26. var emailID=document.form1.email;//this is the email address field
  27. //alert(emailID);
  28. if ((emailID.value==null)||(emailID.value=="")){
  29.                 alert("Please Enter your Email");
  30.                 emailID.focus();
  31.                 return false;
  32.         }
  33.         //alert('after checking null');
  34.         if (echeck(emailID.value)==false){
  35.                 emailID.value="";
  36.                 emailID.focus();
  37.                 return false;
  38.         }
  39.    // alert("something else");
  40.  
  41. //alert("returning 44444");
  42.    var checkInt = document.form1.ssn.value;
  43.    //alert(checkInt.value);
  44.    var isInt = new Boolean(true);
  45.     isInt = this.isInteger(checkInt);
  46.     if(isInt != true){
  47.         return false;
  48.     }
  49. /*var checkZip = document.form1.zip;
  50.   // alert(checkInt.value);
  51. //  textfield2
  52.    var isInt = new Boolean(true);
  53.     isInt = this.isInteger(checkZip.value);
  54.     if(isInt != true){
  55.         zip.focus();
  56.         return false;
  57.     }
  58. */
  59. }
  60. function echeck(str) {
  61.  
  62.                 var at="@";
  63.                 var dot=".";
  64.                 var lat=str.indexOf(at);
  65.                 var lstr=str.length;
  66.                 var ldot=str.indexOf(dot);
  67.                 if (str.indexOf(at)==-1){
  68.                    alert("Invalid E-mail ID");
  69.                    return false;
  70.                 }
  71.  
  72.                 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
  73.                    alert("Invalid E-mail ID");
  74.                    return false;
  75.                 }
  76.  
  77.                 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
  78.                     alert("Invalid E-mail ID");
  79.                     return false;
  80.                 }
  81.  
  82.                  if (str.indexOf(at,(lat+1))!=-1){
  83.                     alert("Invalid E-mail ID");
  84.                     return false;
  85.                  }
  86.  
  87.                  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
  88.                     alert("Invalid E-mail ID");
  89.                     return false;
  90.                  }
  91.  
  92.                  if (str.indexOf(dot,(lat+2))==-1){
  93.                     alert("Invalid E-mail ID");
  94.                     return false;
  95.                  }
  96.  
  97.                  if (str.indexOf(" ")!=-1){
  98.                     alert("Invalid E-mail ID");
  99.                     return false;
  100.                  }
  101.  
  102.                   return true;
  103.         }
  104.     function IsEmpty(fld){
  105.         if (fld.value.length == 0) {
  106.             fld.focus();
  107.             alert("You have left some field empty. Please recheck & try again");
  108.         }
  109.         return true;
  110.  
  111.     }
  112.  
  113.  
  114. function isInteger(s)
  115. {
  116.       var i;
  117.         s = s.toString();
  118.         //alert("returning");
  119.       for (i = 0; i < s.length; i++)
  120.       {
  121.          var c = s.charAt(i);
  122.          if (isNaN(c))
  123.            {
  124.                 alert("Given value is not a number");
  125.                 return false;
  126.            }
  127.        //alert("returning true");
  128.       }
  129.       return true;
  130. }
  131.  
  132.  
  133.  
  134.  
  135. function trim(s)
  136. {
  137.   return s.replace(/^\s+|\s+$/, '');
  138. }
  139. </script>
  140.  
  141.  
  142.  
  143. <form id="form1" name="form1" method="post" action="form.php" onsubmit="return validateFormOnSubmit(this)">
  144.  
  145.  
Sep 23 '10 #1
2 1758
Dormilich
8,652 Expert Mod 8TB
are there any error messages? (I’d hazard a guess at "IsEmpty() is null or undefined")

the IsEmpty() function doesn’t make sense. it returns true in all cases.

the isInteger() function is IMO too complicated. why not checking the whole value with isNaN() or compare the value with parseInt()?
Sep 23 '10 #2
thanks Dormilich for your response but i get the solution from bytes.com i delete that code anyway thanks for your response.
Sep 23 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by hoz | last post: by
6 posts views Thread by abdullah1983 | last post: by
1 post views Thread by Bigpond News Server | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.