Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | oninvalid Event Attribute

  • Difficulty Level : Basic
  • Last Updated : 03 Aug, 2021

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:

  • <input>


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

<element oninvalid = "script">

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


<!DOCTYPE html>
        <title>oninvalid Event Attribute</title>
            h1 {
            body {
        <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">


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

  • Chrome
  • Internet Explorer 10.0
  • Firefox
  • Opera

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!