Javascript DOM oninvalid Event via HTML Tag oninvalid function

Introduction

In JavaScript:

object.oninvalid = function(){
       myScript};

View 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>// www  . j a v  a  2  s .  c o  m

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

function myFunction() {
  document.getElementById("demo").innerHTML = "You must fill out the form!";
}
</script>

</body>
</html>
Bubbles: No
Cancelable: Yes
Event type: Event
Supported HTML tags: <input>



PreviousNext

Related