Javascript examples for DOM Event:addEventListener
The oninvalid event occurs when a submittable <input> element is invalid.
Bubbles | No |
---|---|
Cancelable | Yes |
Supported HTML tags: | <input> |
<!DOCTYPE html> <html> <body> <form action="/action_page.php" method="get"> Name: <input type="text" id="myInput" name="fname" required> <input type="submit" value="Submit"> </form>//from w w w. ja va 2s . c o m <script> document.getElementById("myInput").addEventListener("invalid", myFunction); function myFunction() { console.log("You must fill out the form!"); } </script> </body> </html>