Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript exit method

Tags:

javascript

I have a JavaScript method that i want to validate a form

if the validation fails so

if (validationChecks ...... ){
    return alert("message")
}
else{
//proceed
}

however no matter what i do in the if the form still seems to submit, any ideas?

like image 236
tommy Avatar asked Nov 30 '22 11:11

tommy


2 Answers

you should return false after checking validation.


if (validationChecks ...... ){ 
     alert("message") 
    return false; } 
else{ 
//procced 
} 
like image 91
valli Avatar answered Dec 03 '22 00:12

valli


You have spelt 'return' wrong. Also, returning an alert will not work, you'll need to return false explicitly to stop the form submitting.

if (validationChecks ...... ){ 
    alert("message");
    return false; 
} 
else{ 
//procced 
} 
like image 21
Mark Bell Avatar answered Dec 02 '22 23:12

Mark Bell