เหตุการณ์ oninvalid จะถูกทริกเกอร์หากค่าฟิลด์ที่เพิ่มใน ไม่ถูกต้อง เพิ่มข้อความหากผู้ใช้ลืมกรอกแบบฟอร์มก่อนส่ง
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีใช้งาน oninvalid เหตุการณ์ใน 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>