oninvalid = myFunction(); - Javascript DOM Event

Javascript examples for DOM Event:Element Event Attribute

Description

The oninvalid event occurs when a submittable <input> element is invalid.

Summary

Bubbles No
Cancelable Yes
Supported HTML tags: <input>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php" method="get">
  Name: <input type="text" id="myInput" name="fname" required>
  <input type="submit" value="Submit">
</form>/*from w  w w  .  j a  v  a  2 s  .co m*/

<script>
document.getElementById("myInput").oninvalid = function() {myFunction()};

function myFunction() {
    console.log("You must fill out the form!");
}
</script>

</body>
</html>

Related Tutorials