Input Password required Attribute

Definition and Usage

required Sets or returns whether the password field must be filled out before submitting the form.

This attribute reflects the HTML required attribute.

See also:

HTML Reference Manual:HTML <input> required Attribute

Example

Example 1

Determine whether the password field must be filled out before submitting the form:

var x = document.getElementById("myPassword").required;

Try it yourself

Example 2

Set the password field as a required part of the form submission:

document.getElementById("myPassword").required = true;

Try it yourself

Syntax

Return the required attribute:

passwordObject.required

Set the required attribute:

passwordObject.required = true|false

Attribute value

Value Description
true|false

The password field should be a required part of the form submission.

  • true - The password field is a required part of the form submission
  • false - Default. The password field is not a required part of the form submission

Technical Details

Return value: Boolean value, returned if the password field is a required part of the form submission true; otherwise return false

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support