Open In App
Related Articles

HTML | oninvalid Event Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

The oninvalid event attribute works when an input field values are invalid or empty. The script run when a user clicks on the submit button. The required input field must be filled before submitting it.
Supported Tags:

Syntax: 
 

<element oninvalid = "script">

Attribute Value: This attribute contains single value script which works when oninvalid attribute called. It is supported by all HTML elements.
Example: 
 

html




<!DOCTYPE html>
<html>
    <head>
        <title>oninvalid Event Attribute</title>
        <style>
            h1 {
                color:green;
            }
            body {
                text-align:center;
            }
        </style>
    </head>
    <body>
        <h1>GeeksForGeeks</h1>
        <h2>oninvalid Event Attribute</h2>
        <form action="#" method="post">
            First Name : <input type = "text" oninvalid =
            alert('Please Fill all input field!') required><br><br>
            Last Name : <input type = "text" oninvalid =
            alert('Please Fill all input field!') required><br>
            <input type="submit" value="Submit">
        </form>
    </body>
</html>                   


Output: 
 

Supported Browsers: The browser supported by oninvalid event attribute are listed below: 
 

  • Chrome 10
  • Edge 12
  • Internet Explorer 10
  • Firefox 4
  • Opera 10
  • Safari 5

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Aug, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials