Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Text required property

Input Text required property

Input Text Object Reference The Input Text object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.
  • true - the text field is a required part of the form submission
  • false - default. the text field is not 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


    Input Text Object Reference The Input Text object