Home >Web Front-end >HTML Tutorial >In JavaScript, what is the purpose of the 'oninvalid' event?

In JavaScript, what is the purpose of the 'oninvalid' event?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-09-21 23:45:121510browse

In JavaScript, what is the purpose of the oninvalid event?

If the field value added in is invalid, the oninvalid event will be triggered. Add a message if the user forgets to fill out the form before submitting.

Example

You can try running the following code to understand how to implement the oninvalid event in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         function resetFunct() {
            alert("The form was reset");
         }
      </script>
     
       <form>
         Enter Name: <input type="text"
         required oninvalid = "alert(&#39;Fill the form before submitting!&#39;);" >  <br>
         Enter birth month: <input type=  "text"> <br>
         <input type = "submit">
         <input type = "reset">
      </form>
   </body>
</html>

The above is the detailed content of In JavaScript, what is the purpose of the 'oninvalid' event?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete