Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

HTMLInputElement: input type, state, and constraints

Learn six HTMLInputElement properties for choosing an input type, reading checked state, setting constraints, and disabling a control. Distinguish current state from initial attributes and a validation message from the validation result itself.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

input.validationMessage; input.minLength = 3; input.type = "text"; input.checked = true; input.max = "10"; input.disabled = true;

HTMLInputElement is the browser DOM interface for input controls, not part of ECMAScript itself. type is a string selecting the control kind, such as text, number, or checkbox; the kind determines which other constraints apply. These properties are widely available in modern browsers, but UI support for individual input types can differ. Node 24 alone does not establish support for this API.

minLength is the numeric reflection of minlength: it sets the minimum text length in UTF-16 code units, not necessarily user-perceived characters. -1 means no minimum. It applies to text-like types, does not require a nonempty value without required, and too-short validation concerns user edits rather than a script assignment alone. max is a string, such as "10", that sets the upper bound for numeric, date, or time values on applicable types; it does not limit text length like maxLength. With type="time", times of day are periodic: if min is later than max, the allowed range runs from min through midnight to max. For example, with min="22:00" and max="02:00", 23:00 is within the range even though it is later than max.

checked is a boolean describing the current checked state of a checkbox or radio, not its textual value. The checked attribute specifies the default state, reflected by defaultChecked; changing current checkedness does not update that attribute. disabled reflects a boolean attribute: setting it to true prevents interaction, excludes the control from submitted form data, and bars it from constraint validation. It is not equivalent to readOnly.

validationMessage is a read-only string containing a localized error message, or "" when the control satisfies its constraints or is excluded from validation. An empty message therefore does not prove that a disabled control has a valid value. Set a custom message with setCustomValidity() and clear it with setCustomValidity(""). The example tests message emptiness instead of language-dependent wording and does not attempt to demonstrate a minLength error through script assignment.

Reference identifiers covered by this entry: HTMLInputElement.validationMessage, HTMLInputElement.minLength, HTMLInputElement.type, HTMLInputElement.checked, HTMLInputElement.max, HTMLInputElement.disabled.

Examples

(() => {
  const text = document.createElement("input");
  text.type = "text";
  text.minLength = 3;
  console.log(text.type, text.minLength);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.checked = true;
  console.log(box.checked, box.defaultChecked);

  const number = document.createElement("input");
  number.type = "number";
  number.max = "10";
  number.value = "11";
  console.log(number.max, number.validity.rangeOverflow);
  console.log(number.validationMessage !== "");

  number.disabled = true;
  console.log(number.disabled, number.willValidate);
  console.log(number.validationMessage === "");
})();

Result

text 3
true false
10 true
true
true false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources