What is the usage of oninvalid event in JavaScript?



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>
Updated on: 2020-05-22T11:17:18+05:30

283 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements