James Taylor James Taylor - 3 years ago 141
HTML Question

onClick() to perform function?

Is it possible for in a form of username and password to perform JS validation with the onClick()?
Here is the code:

<form action="signup.php" method="post" name="formInput" onclick="validateForm()">
Username: <br> <input type="text" name="username" placeholder="Username"><br>
Password <br> <input type="password" name="pass" placeholder="Password"><br>
<input type="submit" name="submit">
</form>


I remember doing it before but cannot remember where to call the actual onClick() in the form creation or in the button submission?

Thanks for any suggestions.

Answer Source
<script>
function validateForm() {
   // if valid return true else false
}
</script>

<form action="signup.php" method="post" name="formInput" onsubmit="return validateForm()">
    Username: <br> <input type="text" name="username" placeholder="Username"><br>
    Password  <br> <input type="password" name="pass" placeholder="Password"><br>
    <input type="submit" name="submit">
</form>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download