HTML oninvalid Event Attribute

Description

The event attribute oninvalid allows you to set the script to fire when the submitted form element has been checked and does not meet the form restrictions (for example, the required field is not filled - the required attribute).

Syntax

<element oninvalid="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>oninvalid event</title> 
    </head> 
    <body> 
    <form action="#" method="get">
    Click submit: <br>
    <input type="text" oninvalid="testFunction()" name="info" required><br> 
    <input type="submit" value="Submit"> 
    </form> 
<script> 
function testFunction() { 
  alert ("You did not fill out the required field!"); 
} 
</script> 
  </body> 
</html>

Supported Tags

<input>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XXYesYesYesX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesYesXYes