Javascript DOM oninvalid Event via HTML Tag oninvalid attribute

Introduction

If you click submit, without filling out the text field, an alert message will occur.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>
<script>
function test(){//from  w  ww  .  j  av a  2s .com
   document.getElementById("demo").innerHTML = "You must fill out the form!";
}
</script>
<form action="/action_page.php" method="get">
  Name: <input type="text" 
  oninvalid="test();" name="fname" required>
  <input type="submit" value="Submit">
</form>
</body>
</html>
Bubbles: No
Cancelable: Yes
Event type: Event
Supported HTML tags: <input>



PreviousNext

Related