My return false statement doens't work in Chrome when I want to check the user input through javasript. It fires the action tag even when I return false. Here's my code
<script type="text/javascript">
function testInput(){
if(document.getElementById("input1").value == ""){
alert('error');
return false;
}else{
return true;
}
}
</script>
The HTML
<form action="exec.php" method="post" onSubmit="return testInput()">
<input type="text" id="input1" name="input1" />
<input type="submit" value="Exec" />
</form>
I know I'm late but this reply may help somebody in the future. I encountered the same issue today. After reading Jack's comment I inserted a try/catch block in my check function. This allowed me to prevent execution to stop (returns false even if the code crashes) and to print the error in the Chrome console panel. You can try the same like so :
function testInput(){
try {
if (document.getElementById("input1").value == "") {
alert('error');
return false;
} else {
return true;
}
} catch (e) {
console.error(e.message);
return false;
}
}