-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
293 lines (157 loc) · 18.2 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
---
title: HTMLInputElement
slug: Web/API/HTMLInputElement
page-type: web-api-interface
browser-compat: api.HTMLInputElement
---
{{APIRef("HTML DOM")}}
The **`HTMLInputElement`** interface provides special properties and methods for manipulating the options, layout, and presentation of {{HtmlElement("input")}} elements.
{{InheritanceDiagram}}
## Instance properties
_Also inherits properties from its parent interface, {{domxref("HTMLElement")}}._
Some properties only apply to input element types that support the corresponding attributes.
- {{domxref("HTMLInputElement.align", "align")}} {{Deprecated_Inline}}
- : A string that represents the alignment of the element. _Use CSS instead._
- {{domxref("HTMLInputElement.defaultValue", "defaultValue")}}
- : A string that represents the default value as originally specified in the HTML that created this object.
- {{domxref("HTMLInputElement.dirName", "dirName")}}
- : A string that represents the directionality of the element.
- {{domxref("HTMLInputElement.incremental", "incremental")}} {{Non-standard_Inline}}
- : A boolean that represents the search event fire mode, if `true`, fires on every keypress, or on clicking the cancel button; otherwise fires when pressing <kbd>Enter</kbd>.
- {{domxref("HTMLInputElement.labels", "labels")}} {{ReadOnlyInline}}
- : Returns a list of {{ HTMLElement("label") }} elements that are labels for this element.
- {{domxref("HTMLInputElement.list", "list")}} {{ReadOnlyInline}}
- : Returns the element pointed to by the [`list`](/en-US/docs/Web/HTML/Element/input#list) attribute. The property may be `null` if no HTML element is found in the same tree.
- {{domxref("HTMLInputElement.multiple", "multiple")}}
- : A boolean that represents the element's [`multiple`](/en-US/docs/Web/HTML/Element/input#multiple) attribute, indicating whether more than one value is possible (e.g., multiple files).
- {{domxref("HTMLInputElement.name", "name")}}
- : A string that represents the element's [`name`](/en-US/docs/Web/HTML/Element/input#name) attribute, containing a name that identifies the element when submitting the form.
- {{domxref("HTMLInputElement.popoverTargetAction", "popoverTargetAction")}}
- : Gets and sets the action to be performed (`"hide"`, `"show"`, or `"toggle"`) on a popover element being controlled by an {{htmlelement("input")}} element of `type="button"`. It reflects the value of the [`popovertargetaction`](/en-US/docs/Web/HTML/Element/input#popovertargetaction) HTML attribute.
- {{domxref("HTMLInputElement.popoverTargetElement", "popoverTargetElement")}}
- : Gets and sets the popover element to control via an {{htmlelement("input")}} element of `type="button"`. The JavaScript equivalent of the [`popovertarget`](/en-US/docs/Web/HTML/Element/input#popovertarget) HTML attribute.
- {{domxref("HTMLInputElement.step", "step")}}
- : A string that represents the element's [`step`](/en-US/docs/Web/HTML/Element/input#step) attribute, which works with [`min`](/en-US/docs/Web/HTML/Element/input#min) and [`max`](/en-US/docs/Web/HTML/Element/input#max) to limit the increments at which a numeric or date-time value can be set. It can be the string `any` or a positive floating point number. If this is not set to `any`, the control accepts only values at multiples of the step value greater than the minimum.
- {{domxref("HTMLInputElement.type", "type")}}
- : A string that represents the element's [`type`](/en-US/docs/Web/HTML/Element/input#type) attribute, indicating the type of control to display. For possible values, see the documentation for the [`type`](/en-US/docs/Web/HTML/Element/input#type) attribute.
- {{domxref("HTMLInputElement.useMap", "useMap")}} {{Deprecated_Inline}}
- : A string that represents a client-side image map.
- {{domxref("HTMLInputElement.value", "value")}}
- : A string that represents the current value of the control. If the user enters a value different from the value expected, this may return an empty string.
- {{domxref("HTMLInputElement.valueAsDate", "valueAsDate")}}
- : A {{jsxref("Date")}} that represents the value of the element, interpreted as a date, or `null` if conversion is not possible.
- {{domxref("HTMLInputElement.valueAsNumber", "valueAsNumber")}}
- : A number that represents the value of the element, interpreted as one of the following, in order: A time value, a number, or `NaN` if conversion is impossible.
### Instance properties related to the parent form
- {{domxref("HTMLInputElement.form", "form")}} {{ReadOnlyInline}}
- : Returns a reference to the parent {{HtmlElement("form")}} element.
- {{domxref("HTMLInputElement.formAction", "formAction")}}
- : A string that represents the element's [`formaction`](/en-US/docs/Web/HTML/Element/input#formaction) attribute, containing the URL of a program that processes information submitted by the element. This overrides the [`action`](/en-US/docs/Web/HTML/Element/form#action) attribute of the parent form.
- {{domxref("HTMLInputElement.formEnctype", "formEnctype")}}
- : A string that represents the element's [`formenctype`](/en-US/docs/Web/HTML/Element/input#formenctype) attribute, containing the type of content that is used to submit the form to the server. This overrides the [`enctype`](/en-US/docs/Web/HTML/Element/form#enctype) attribute of the parent form.
- {{domxref("HTMLInputElement.formMethod", "formMethod")}}
- : A string that represents the element's [`formmethod`](/en-US/docs/Web/HTML/Element/input#formmethod) attribute, containing the HTTP method that the browser uses to submit the form. This overrides the [`method`](/en-US/docs/Web/HTML/Element/form#method) attribute of the parent form.
- {{domxref("HTMLInputElement.formNoValidate", "formNoValidate")}}
- : A boolean that represents the element's [`formnovalidate`](/en-US/docs/Web/HTML/Element/input#formnovalidate) attribute, indicating that the form is not to be validated when it is submitted. This overrides the [`novalidate`](/en-US/docs/Web/HTML/Element/form#novalidate) attribute of the parent form.
- {{domxref("HTMLInputElement.formTarget", "formTarget")}}
- : A string that represents the element's [`formtarget`](/en-US/docs/Web/HTML/Element/input#formtarget) attribute, containing a name or keyword indicating where to display the response that is received after submitting the form. This overrides the [`target`](/en-US/docs/Web/HTML/Element/form#target) attribute of the parent form.
### Instance properties that apply to any type of input element that is not hidden
- {{domxref("HTMLInputElement.disabled", "disabled")}}
- : A boolean that represents the element's [`disabled`](/en-US/docs/Web/HTML/Element/input#disabled) attribute, indicating that the control is not available for interaction. The input values will not be submitted with the form. See also [`readonly`](/en-US/docs/Web/HTML/Element/input#readonly).
- {{domxref("HTMLInputElement.required", "required")}}
- : A boolean that represents the element's [`required`](/en-US/docs/Web/HTML/Element/input#required) attribute, indicating that the user must fill in a value before submitting a form.
- {{domxref("HTMLInputElement.validationMessage", "validationMessage")}} {{ReadOnlyInline}}
- : Returns a localized message that describes the validation constraints that the control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation ([`willValidate`](/en-US/docs/Web/API/HTMLObjectElement/willValidate) is `false`), or it satisfies its constraints. This value can be set by the {{domxref("HTMLInputElement.setCustomValidity()", "setCustomValidity()")}} method.
- {{domxref("HTMLInputElement.validity", "validity")}} {{ReadOnlyInline}}
- : Returns the element's current validity state.
- {{domxref("HTMLInputElement.willValidate", "willValidate")}} {{ReadOnlyInline}}
- : Returns whether the element is a candidate for constraint validation. It is `false` if any conditions bar it from constraint validation, including: its `type` is one of `hidden`, `reset` or `button`, it has a {{HTMLElement("datalist")}} ancestor or its `disabled` property is `true`.
### Instance properties that apply only to elements of type checkbox or radio
- {{domxref("HTMLInputElement.checked", "checked")}}
- : A boolean that represents the current state of the element.
- {{domxref("HTMLInputElement.defaultChecked", "defaultChecked")}}
- : A boolean that represents the default state of a radio button or checkbox as originally specified in HTML that created this object.
- {{domxref("HTMLInputElement.indeterminate", "indeterminate")}}
- : A boolean that represents whether the checkbox or radio button is in indeterminate state. For checkboxes, the effect is that the appearance of the checkbox is obscured/greyed in some way as to indicate its state is indeterminate (not checked but not unchecked). Does not affect the value of the `checked` attribute, and clicking the checkbox will set the value to false.
### Instance properties that apply only to elements of type image
- {{domxref("HTMLInputElement.alt", "alt")}}
- : A string that represents the element's [`alt`](/en-US/docs/Web/HTML/Element/input#alt) attribute, containing alternative text to use.
- {{domxref("HTMLInputElement.height", "height")}}
- : A string that represents the element's [`height`](/en-US/docs/Web/HTML/Element/input#height) attribute, which defines the height of the image displayed for the button.
- {{domxref("HTMLInputElement.src", "src")}}
- : A string that represents the element's [`src`](/en-US/docs/Web/HTML/Element/input#src) attribute, which specifies a URI for the location of an image to display on the graphical submit button.
- {{domxref("HTMLInputElement.width", "width")}}
- : A string that represents the element's [`width`](/en-US/docs/Web/HTML/Element/input#width) attribute, which defines the width of the image displayed for the button.
### Instance properties that apply only to elements of type file
- {{domxref("HTMLInputElement.accept", "accept")}}
- : A string that represents the element's [`accept`](/en-US/docs/Web/HTML/Element/input#accept) attribute, containing comma-separated list of file types that can be selected.
- {{domxref("HTMLInputElement.files", "files")}}
- : A {{domxref("FileList")}} that represents the files selected for upload.
- {{domxref("HTMLInputElement.webkitdirectory", "webkitdirectory")}}
- : A boolean that represents the [`webkitdirectory`](/en-US/docs/Web/HTML/Element/input#webkitdirectory) attribute. If `true`, the file-system-picker interface only accepts directories instead of files.
- {{domxref("HTMLInputElement.webkitEntries", "webkitEntries")}} {{ReadOnlyInline}}
- : Describes the currently selected files or directories.
### Instance properties that apply only to visible elements containing text or numbers
- {{domxref("HTMLInputElement.autocomplete", "autocomplete")}}
- : A string that represents the element's [`autocomplete`](/en-US/docs/Web/HTML/Element/input#autocomplete) attribute, indicating whether the value of the control can be automatically completed by the browser.
- {{domxref("HTMLInputElement.capture", "capture")}}
- : A string that represents the element's [`capture`](/en-US/docs/Web/HTML/Element/input#capture) attribute, indicating the media capture input method in file upload controls.
- {{domxref("HTMLInputElement.max", "max")}}
- : A string that represents the element's [`max`](/en-US/docs/Web/HTML/Element/input#max) attribute, containing the maximum (numeric or date-time) value for this item, which must not be less than its minimum ([`min`](/en-US/docs/Web/HTML/Element/input#min) attribute) value.
- {{domxref("HTMLInputElement.maxLength", "maxLength")}}
- : A number that represents the element's [`maxlength`](/en-US/docs/Web/HTML/Element/input#maxlength) attribute, containing the maximum number of characters (in Unicode code points) that the value can have.
- {{domxref("HTMLInputElement.min", "min")}}
- : A string that represents the element's [`min`](/en-US/docs/Web/HTML/Element/input#min) attribute, containing the minimum (numeric or date-time) value for this item, which must not be greater than its maximum ([`max`](/en-US/docs/Web/HTML/Element/input#max) attribute) value.
- {{domxref("HTMLInputElement.minLength", "minLength")}}
- : A number that represents the element's [`minlength`](/en-US/docs/Web/HTML/Element/input#minlength) attribute, containing the minimum number of characters (in Unicode code points) that the value can have.
- {{domxref("HTMLInputElement.pattern", "pattern")}}
- : A string that represents the element's [`pattern`](/en-US/docs/Web/HTML/Element/input#pattern) attribute, containing a regular expression that the control's value is checked against. Use the [`title`](/en-US/docs/Web/HTML/Element/input#title) attribute to describe the pattern to help the user. This attribute only applies when the value of the [`type`](/en-US/docs/Web/HTML/Element/input#type) attribute is `text`, `search`, `tel`, `url` or `email`.
- {{domxref("HTMLInputElement.placeholder", "placeholder")}}
- : A string that represents the element's [`placeholder`](/en-US/docs/Web/HTML/Element/input#placeholder) attribute, containing a hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds. This attribute only applies when the value of the [`type`](/en-US/docs/Web/HTML/Element/input#type) attribute is `text`, `search`, `tel`, `url` or `email`.
- {{domxref("HTMLInputElement.readOnly", "readOnly")}}
- : A boolean that represents the element's [`readonly`](/en-US/docs/Web/HTML/Element/input#readonly) attribute, indicating that the user cannot modify the value of the control. This is ignored if the [`type`](/en-US/docs/Web/HTML/Element/input#type) is `hidden`, `range`, `color`, `checkbox`, `radio`, `file`, or a button type.
- {{domxref("HTMLInputElement.selectionDirection", "selectionDirection")}}
- : A string that represents the direction in which selection occurred. Possible values are: `forward` (the selection was performed in the start-to-end direction of the current locale), `backward` (the opposite direction) or `none` (the direction is unknown).
- {{domxref("HTMLInputElement.selectionEnd", "selectionEnd")}}
- : A number that represents the end index of the selected text. When there's no selection, this returns the offset of the character immediately following the current text input cursor position.
- {{domxref("HTMLInputElement.selectionStart", "selectionStart")}}
- : A number that represents the beginning index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the {{HTMLElement("input")}} element.
- {{domxref("HTMLInputElement.size", "size")}}
- : A number that represents the element's [`size`](/en-US/docs/Web/HTML/Element/input#size) attribute, containing visual size of the control. This value is in pixels unless the value of [`type`](/en-US/docs/Web/HTML/Element/input#type) is `text` or `password`, in which case, it is an integer number of characters. Applies only when [`type`](/en-US/docs/Web/HTML/Element/input#type) is set to `text`, `search`, `tel`, `url`, `email`, or `password`.
## Instance methods
_Also inherits methods from its parent interface, {{domxref("HTMLElement")}}._
- {{domxref("HTMLInputElement.checkValidity()", "checkValidity()")}}
- : Returns a boolean value that is `false` if the element is a candidate for constraint validation, and it does not satisfy its constraints. In this case, it also fires an {{domxref("HTMLInputElement/invalid_event", "invalid")}} event at the element. It returns `true` if the element is not a candidate for constraint validation, or if it satisfies its constraints.
- {{domxref("HTMLInputElement.reportValidity()", "reportValidity()")}}
- : Runs the `checkValidity()` method, and if it returns false (for an invalid input or no pattern attribute provided), then it reports to the user that the input is invalid in the same manner as if you submitted a form.
- {{domxref("HTMLInputElement.select()", "select()")}}
- : Selects all the text in the input element, and focuses it so the user can subsequently replace all of its content.
- {{domxref("HTMLInputElement.setCustomValidity()", "setCustomValidity()")}}
- : Sets a custom validity message for the element. If this message is not the empty string, then the element is suffering from a custom validity error, and does not validate.
- {{domxref("HTMLInputElement.setRangeText()", "setRangeText()")}}
- : Replaces a range of text in the input element with new text.
- {{domxref("HTMLInputElement.setSelectionRange()", "setSelectionRange()")}}
- : Selects a range of text in the input element (but does not focus it).
- {{domxref("HTMLInputElement.showPicker()", "showPicker()")}}
- : Shows a browser picker for date, time, color, and files.
- {{domxref("HTMLInputElement.stepDown()", "stepDown()")}}
- : Decrements the [`value`](/en-US/docs/Web/HTML/Element/input#value) by ([`step`](/en-US/docs/Web/HTML/Element/input#step) \* n), where n defaults to 1 if not specified.
- {{domxref("HTMLInputElement.stepUp()", "stepUp()")}}
- : Increments the [`value`](/en-US/docs/Web/HTML/Element/input#value) by ([`step`](/en-US/docs/Web/HTML/Element/input#step) \* n), where n defaults to 1 if not specified.
## Events
_Also inherits events from its parent interface, {{domxref("HTMLElement")}}._
Listen to these events using {{domxref("EventTarget.addEventListener", "addEventListener()")}} or by assigning an event listener to the `oneventname` property of this interface:
- {{domxref("HTMLInputElement/invalid_event", "invalid")}} event
- : Fired when an element does not satisfy its constraints during constraint validation.
- {{domxref("HTMLInputElement/search_event", "search")}} event {{Non-standard_Inline}}
- : Fired when a search is initiated on an {{HTMLElement("input")}} of `type="search"`.
- {{domxref("HTMLInputElement/select_event", "select")}} event
- : Fired when some text has been selected.
- {{domxref("HTMLInputElement/selectionchange_event", "selectionchange")}} event {{Experimental_Inline}}
- : Fires when the text selection in a {{HTMLElement("input")}} element has been changed.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- HTML element implementing this interface: {{ HTMLElement("input") }}