| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since December 2018.
The invalid event fires when a submittable element has been checked for validity and doesn't satisfy its constraints.
This event can be useful for displaying a summary of the problems with a form on submission. When a form is submitted, invalid events are fired at each form control that is invalid. The validity of submittable elements is checked before submitting their owner <form>, or after the checkValidity() method of the element or its owner <form> is called.
It is not checked on blur.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("invalid", (event) => { })
oninvalid = (event) => { }
A generic Event.
If a form is submitted with an invalid value, the submittable elements are checked and, if an error is found, the invalid event will fire on the invalid element. In this example, when an invalid event fires because of an invalid value in the input, the invalid value is logged.
<form action="#">
<div>
<label>
Enter an integer between 1 and 10:
<input type="number" min="1" max="10" required />
</label>
</div>
<div><input type="submit" value="submit" /></div>
</form>
<hr />
Invalid values:
<ul id="log"></ul>
const input = document.querySelector("input");
const log = document.getElementById("log");
input.addEventListener("invalid", (e) => {
log.appendChild(document.createElement("li")).textContent = JSON.stringify(
e.target.value,
);
});
| Specification |
|---|
| HTML # event-invalid |
| HTML # handler-oninvalid |
This page was last modified on Sep 25, 2025 by MDN contributors.
HTMLInputElementacceptalphaaltautocompletecapturecheckedcolorSpacedefaultCheckeddefaultValuedirNamedisabledfilesformformActionformEnctypeformMethodformNoValidateformTargetheightindeterminatelabelslistmaxmaxLengthminminLengthmultiplenamepatternplaceholderpopoverTargetActionpopoverTargetElementreadOnlyrequiredselectionDirectionselectionEndselectionStartsizesrcsteptypevalidationMessagevalidityvaluevalueAsDatevalueAsNumberwebkitdirectorywebkitEntrieswidthwillValidateBeforeUnloadEventDOMStringMapErrorEventHTMLAnchorElementHTMLAreaElementHTMLAudioElementHTMLBRElementHTMLBaseElementHTMLBodyElementHTMLButtonElementHTMLCanvasElementHTMLDListElementHTMLDataElementHTMLDataListElementHTMLDialogElementHTMLDivElementHTMLDocumentHTMLElementHTMLEmbedElementHTMLFieldSetElementHTMLFormControlsCollectionHTMLFormElementHTMLFrameSetElementHTMLGeolocationElementHTMLHRElementHTMLHeadElementHTMLHeadingElementHTMLHtmlElementHTMLIFrameElementHTMLImageElementHTMLLIElementHTMLLabelElementHTMLLegendElementHTMLLinkElementHTMLMapElementHTMLMediaElementHTMLMenuElementHTMLMetaElementHTMLMeterElementHTMLModElementHTMLOListElementHTMLObjectElementHTMLOptGroupElementHTMLOptionElementHTMLOptionsCollectionHTMLOutputElementHTMLParagraphElementHTMLPictureElementHTMLPreElementHTMLProgressElementHTMLQuoteElementHTMLScriptElementHTMLSelectElementHTMLSourceElementHTMLSpanElementHTMLStyleElementHTMLTableCaptionElementHTMLTableCellElementHTMLTableColElementHTMLTableElementHTMLTableRowElementHTMLTableSectionElementHTMLTemplateElementHTMLTextAreaElementHTMLTimeElementHTMLTitleElementHTMLTrackElementHTMLUListElementHTMLUnknownElementHTMLVideoElementHashChangeEventHistoryImageDataLocationMessageChannelMessageEventMessagePortNavigatorPageRevealEventPageSwapEventPageTransitionEventPluginPluginArrayPromiseRejectionEventRadioNodeListTimeRangesUserActivationValidityStateWindowWorkletGlobalScopeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |