Input Text required property
Example
Check whether the text field has been filled before submission:
var x = document.getElementById("myText").required;
x The output is:
true
Try it »
Definition and Usage
The required property is used to set or return whether the text field must be filled before submission.
This attribute reflects the HTML required attribute.
Browser support





All major browsers support the required property, except Internet Explorer 9 and earlier IE versions and the Safari browser.
Syntax
Return the required property:
textObject
.required
Set the required property:
textObject
.required=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Specifies whether the text field is a required part of the form submission.
|
Technical Details
| Return value: | Boolean, returns true if the text field is a required part of the form submission, otherwise returns false |
|---|
More examples
Example
Set the text field as a required part of the form submission:
document.getElementById("myText").required = true;
Try it »
Related pages
HTML Reference Manual: HTML required attribute
The Input Text object