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.
Code:
function validateFormOnSubmit() {
var checkEmpty = new Boolean(false);
checkEmpty = this.IsEmpty(ssn);
//checkEmpty = this.IsEmpty(dob);
checkEmpty = this.IsEmpty(lname);
checkEmpty = this.IsEmpty(fname);
checkEmpty = this.IsEmpty(middle_initial);
checkEmpty = this.IsEmpty(spouse_lname);
checkEmpty = this.IsEmpty(spouse_fname);
checkEmpty = this.IsEmpty(spouse_middle_initial);
checkEmpty = this.IsEmpty(street_no);
checkEmpty = this.IsEmpty(address);
checkEmpty = this.IsEmpty(city);
checkEmpty = this.IsEmpty(zip);
checkEmpty = this.IsEmpty(cell);
checkEmpty = this.IsEmpty(business_phone);
checkEmpty = this.IsEmpty(extention);
checkEmpty = this.IsEmpty(home_phone);
if (checkEmpty == false){
alert("alert");
return false
}
var emailID=document.form1.email;//this is the email address field
//alert(emailID);
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email");
emailID.focus();
return false;
}
//alert('after checking null');
if (echeck(emailID.value)==false){
emailID.value="";
emailID.focus();
return false;
}
// alert("something else");
//alert("returning 44444");
var checkInt = document.form1.ssn.value;
//alert(checkInt.value);
var isInt = new Boolean(true);
isInt = this.isInteger(checkInt);
if(isInt != true){
return false;
}
/*var checkZip = document.form1.zip;
// alert(checkInt.value);
// textfield2
var isInt = new Boolean(true);
isInt = this.isInteger(checkZip.value);
if(isInt != true){
zip.focus();
return false;
}
*/
}
function echeck(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID");
return false;
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID");
return false;
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID");
return false;
}
return true;
}
function IsEmpty(fld){
if (fld.value.length == 0) {
fld.focus();
alert("You have left some field empty. Please recheck & try again");
}
return true;
}
function isInteger(s)
{
var i;
s = s.toString();
//alert("returning");
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (isNaN(c))
{
alert("Given value is not a number");
return false;
}
//alert("returning true");
}
return true;
}
function trim(s)
{
return s.replace(/^\s+|\s+$/, '');
}
</script>
<form id="form1" name="form1" method="post" action="form.php" onsubmit="return validateFormOnSubmit(this)">
Comment