What is the usage of oninvalid event in JavaScript?

HTMLJavascriptProgramming Scripts

The oninvalid event is triggered if the field value added in <input> is invalid. Add a message if the user forgets to fill the form before submission.

Example

You can try to run the following code to learn how to implement 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('Fill the form before submitting!');" >  <br>
         Enter birth month: <input type=  "text"> <br>
         <input type = "submit">
         <input type = "reset">
      </form>
   </body>
</html>
raja
Published on 26-Feb-2018 15:37:31
Advertisements