Input Text required Attribute
Definition and Usage
required
Sets or returns whether the text 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 text field must be filled out before submitting the form:
var x = document.getElementById("myText").required;
Example 2
Set the text field as a required part of the form submission:
document.getElementById("myText").required = true;
Syntax
Return the required attribute:
textObject.required
Set the required attribute:
textObject.required = true|false
Attribute value
Value | Description |
---|---|
true|false |
Specify whether the text field should be a required part of the form submission.
|
Technical Details
Return Value: | Boolean value, returned if the text field is a required part of the form submission. true ; otherwise return false . |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supported | 10.0 | Supported | Not Supported | Supported |