jecommera
asked on
please see what is wrong with my JS form validation
Hi
I am testing some JS and the following code seems to still submit the form even when the confirm if cancelled returns false.
Can you please see why this is happening:
thanks
<html>
<head><title>Id and Name Attributes</title>
<script type="text/javascript">
function readySubmit() {
if (confirm("Are you ready to submit your form?")) {
return true;
}
else {
alert("boo");
return false;
}
}
</script>
</head>
<body>
<form action="submit.php" method="get">
Enter your user id:
<input type="text" name="textbox" value="" />
<br />
Type your password:
<input type = "password" name = "secret" />
<p></p>
<input type="submit" onClick="readySubmit();" />
</form>
</body>
</html>
I am testing some JS and the following code seems to still submit the form even when the confirm if cancelled returns false.
Can you please see why this is happening:
thanks
<html>
<head><title>Id and Name Attributes</title>
<script type="text/javascript">
function readySubmit() {
if (confirm("Are you ready to submit your form?")) {
return true;
}
else {
alert("boo");
return false;
}
}
</script>
</head>
<body>
<form action="submit.php" method="get">
Enter your user id:
<input type="text" name="textbox" value="" />
<br />
Type your password:
<input type = "password" name = "secret" />
<p></p>
<input type="submit" onClick="readySubmit();" />
</form>
</body>
</html>
ASKER
I thought you would return from a function rather than a method?
sorry just trying to get my head around this...
sorry just trying to get my head around this...
I'm not clear on what you are asking, but you have to return false from an onclick to stop the submit from firing.
Does that help?
Does that help?
ASKER
We have return true and return false which I understand says ye or nay to submit
I don't really understand the third return "return readySubmit();"
I don't really understand the third return "return readySubmit();"
ASKER
where is it returning to - the function? Isn't it calling rather than returning?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<input type="submit" onClick="return readySubmit();" />