Link to home
Start Free TrialLog in
Avatar of jecommera
jecommeraFlag for United Kingdom of Great Britain and Northern Ireland

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>
Avatar of onlyaymie
onlyaymie

You need to return your status:

<input type="submit" onClick="return readySubmit();" />
Avatar of jecommera

ASKER

I thought you would return from a function rather than a method?

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?
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();"
where is it returning to - the function? Isn't it calling rather than returning?
ASKER CERTIFIED SOLUTION
Avatar of onlyaymie
onlyaymie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial