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?

WBOY
Release: 2023-09-21 23:45:12
forward
1476 people have browsed it

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>
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template