Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Disabled form controls

Disabled form controls cannot be operated or focused by the user, and their values are not submitted. In JavaScript, the disabled property switches a control's own disabled state, while a containing fieldset can also disable it.

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

control.disabled = true;
control.disabled = false;
control.matches(':disabled');

Disabled form controls are form controls that have been disabled. Users cannot edit them or activate them by clicking; they cannot receive focus and do not participate in constraint validation. Their values are omitted from form submission. This is an HTML and browser DOM mechanism, not a feature of a particular ECMAScript edition. MDN marks HTMLInputElement.disabled as widely available across browsers since July 2015; the presence of Node 24 does not prove DOM support.

The input.disabled property is a boolean reflecting the element's own disabled attribute. Assigning true adds that attribute, and assigning false removes it. The attribute is boolean: even disabled="false" means disabled because its presence, not its textual value, matters.

A disabled fieldset also disables descendant controls, except those inside its first legend element child. Being inside a nested fieldset's legend does not by itself exempt a control from being disabled by the outer fieldset. Consequently, input.disabled can be false while an ancestor still disables the control; use input.matches(':disabled') to check its effective state. Setting input.disabled = false alone does not override disabling imposed by a fieldset.

Do not confuse disabled with readonly: supported read-only fields can still receive focus and contribute their values to form submission. readonly applies to textual input types and textarea, not, for example, select or button. The example demonstrates toggling disabled and the resulting omission of the field from FormData.

Examples

const form = document.createElement('form');
const input = document.createElement('input');
input.name = 'topic';
input.value = 'JavaScript';
form.append(input);

input.disabled = true;
console.log(input.disabled);
console.log(new FormData(form).has('topic'));

input.disabled = false;
console.log(new FormData(form).get('topic'));

Result

true
false
JavaScript

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