HTML | oninvalid Event Attribute
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.
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:
<!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
- Internet Explorer 10.0
- Firefox
- Opera
- HTML | DOM oninvalid Event
- HTML | onpageshow Event Attribute
- HTML | ondragenter Event Attribute
- HTML | onkeyup Event Attribute
- HTML | onchange Event Attribute
- HTML | ondrop Event Attribute
- HTML | onmouseup Event Attribute
- HTML | onkeydown Event Attribute
- HTML | onunload Event Attribute
- HTML | onmouseover Event Attribute
- HTML | ondrag Event Attribute
- HTML | onresize Event Attribute
- HTML | onreset Event Attribute
- HTML | onload Event Attribute
- HTML | ontoggle Event Attribute
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



