0

Ive been trying to get my submit button to return false if there are any error in my code, but it keeps bringing me to a broken page, i have tried in the console of firefox and there are no errors. Thanks the return false is at the bottom Code:

function searchForm(){
//checks all the boxes to see if there are any errors
confirmFName();

confirmLName();

confirmEmail();

confirmAddress1();

confirmAddress2();

confirmCity();

confirmCode();

confirmUName();

confirmPass();

//check to make sure a region is selected
if(nhlForm.regBox == "Choose a Country first", "Choose your Country First"){
    //shows error message
    showMessage(nhlForm.regBox, "error", "*Choose a region");
    showMessage(nhlForm.counBox, "error", "*Choose a country");
}

//checks if checkbox is checked, if not messgae will appear and form will not send
if(nhlForm.agebox.checked == true){
    showMessage(nhlForm.agebox, "bingo", "");
}else{

    //shows error message
    showMessage(nhlForm.agebox, "error", "You must be at least 14 to have an account"); 
}

if(nhlForm.checkbox.checked == true){

    showMessage(nhlForm.checkbox, "bingo", "");
}else{

    //shows error message
    showMessage(nhlForm.checkbox, "error", "You must accept the terms of use to continue"); 
}

//if there are no errors, form will send
if(document.querySelectorAll(".error").length > 0){

//dont submit the form till errors are fixed
return false;
    }
}
3
  • You have to show us how that function is called
    – adeneo
    Apr 24, 2014 at 4:26
  • fiddle please Apr 24, 2014 at 4:31
  • Show where this function is called.. or please show us a fiddle
    – Nidhin S G
    Apr 24, 2014 at 4:37

1 Answer 1

0

Try this code

function searchForm(){
//checks all the boxes to see if there are any errors
confirmFName();

confirmLName();

confirmEmail();

confirmAddress1();

confirmAddress2();

confirmCity();

confirmCode();

confirmUName();

confirmPass();
var flag=true;

//check to make sure a region is selected
if(nhlForm.regBox == "Choose a Country first", "Choose your Country First"){
    //shows error message
    showMessage(nhlForm.regBox, "error", "*Choose a region");
    showMessage(nhlForm.counBox, "error", "*Choose a country");
flag=false;
}

//checks if checkbox is checked, if not messgae will appear and form will not send
if(nhlForm.agebox.checked == true){
    showMessage(nhlForm.agebox, "bingo", "");
}else{

    //shows error message
    showMessage(nhlForm.agebox, "error", "You must be at least 14 to have an account"); 
flag=false;
}

if(nhlForm.checkbox.checked == true){

    showMessage(nhlForm.checkbox, "bingo", "");
}else{

    //shows error message
    showMessage(nhlForm.checkbox, "error", "You must accept the terms of use to continue"); 
flag=false;
}
 return flag;
}

and onSubmit="return searchForm()" in form tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.