THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Input Text required Property

Input Text Object Reference Input Text Object

Example

Find out if a text field must be filled out before submitting a form:

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

The result of x will be:

true
Try it Yourself »

Definition and Usage

The required property sets or returns whether a text field must be filled out before submitting a form.

This property reflects the HTML required attribute.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The required property is supported in all major browsers, except Internet Explorer 9 and earlier versions, and Safari.


Syntax

Return the required property:

textObject.required

Set the required property:

textObject.required=true|false

Property Values

Value Description
true|false Specifies whether a text field should be a required part of form submission.
  • true - The text field is a required part of form submission
  • false - Default. The text field is not a required part of form submission

Technical Details

Return Value: A Boolean, returns true if the text field is a required part of form submission, otherwise it returns false

More Examples

Example

Set a text field to be a required part of form submission:

document.getElementById("myText").required = true;
Try it Yourself »

Related Pages

HTML reference: HTML <input> required attribute


Input Text Object Reference Input Text Object