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.
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('Fill the form before submitting!');" > <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!