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;
}
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.