Input Text requiredProperty
Examples
Check whether the text field has been filled in before submitting the form:
var x = document.getElementById("myText").required;
xThe output result is:
true
Try it Yourself »
Definition and Usage
The required property is used to set or return whether a text field must be filled in before form submission.
This property reflects the HTML required attribute.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the required attribute, except Internet Explorer 9 and earlier IE 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 the text field is a required part of form submission.
|
| Return Value: | A Boolean, returning true if the text field is a required part of form submission, otherwise returns false |
|---|
More Examples
Example
Set the text field as 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 Other Extensions