![]() |
The HTML
oninvalid event attribute specifies a script to be executed when a submittable <input> element is found to be invalid during form validation. This event is typically triggered when a user attempts to submit a form containing an input field that does not meet its defined constraints, such as a required field being empty or a field not matching a specified pattern .
|
Example:
HTML
<input type="text" oninvalid="alert('You must fill out the form!');" required>
The oninvalid event occurs when a submittable <input> element is invalid.
For example, the input field is invalid if the required attribute is set and the field is empty (the required attribute specifies that the input field must be filled out before submitting the form).
The numbers in the table specify the first browser version that fully supports the event attribute
<element oninvalid="script">
Value | Description |
---|---|
script | The script to be run on oninvalid |
Supported HTML tags: | <input> |
---|
If you submit the input field with less than 6 characters, an alert message will occur.
Note: The oninvalid event is not supported in Safari.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
Name: <input type="text" oninvalid="alert('Must contain 6 or more characters');" name="fname" pattern=".{6,}">
<input type="submit" value="Submit">
</form>
<p>If you submit the input field with less than 6 characters, an alert message will occur.</p>
<p><strong>Note:</strong> The oninvalid event is not supported in Safari.</p>
</body>
</html>
If you click submit, without filling out the text field, an alert message will occur.
Note: The oninvalid event is not supported in Safari.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
Name: <input type="text" oninvalid="alert('You must fill out the form!');" name="fname" required>
<input type="submit" value="Submit">
</form>
<p>If you click submit, without filling out the text field, an alert message will occur.</p>
<p><strong>Note:</strong> The oninvalid event is not supported in Safari.</p>
</body>
</html>
html event attributes |
List of Form Events Attribute | Form Events Attribute |
What is HTML onblur Event Attribute | Form Events Attribute |
What is HTML onchange Event Attribute | Form Events Attribute |
What is HTML oncontextmenu Event Attribute | Form Events Attribute |
What is HTML onfocus Event Attribute | Form Events Attribute |
What is HTML oninput Event Attribute | Form Events Attribute |
What is HTML oninvalid Event Attribute | Form Events Attribute |
Example of HTML oninvalid Event Attribute | Form Events Attribute |
Definition and Usage of HTML oninvalid Event Attribute | Form Events Attribute |
Browser Support of HTML oninvalid Event Attribute | Form Events Attribute |
Syntax of HTML oninvalid Event Attribute | Form Events Attribute |
Attribute Values of HTML oninvalid Event Attribute | Form Events Attribute |
Technical Details of HTML oninvalid Event Attribute | Form Events Attribute |
How to Execute a JavaScript when an input field is invalid | Form Events Attribute |
How to add a JavaScript when an input field is invalid | Form Events Attribute |
Read Full: | Form Events Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | Form Events Attribute |
Uploaded by: | Admin |
Views: | 13 |
Reffered: https://www.w3schools.com/tags/ev_oninvalid.asp