Easy Tutorial
❮ Jsref Getutcmonth Dom Obj Legend ❯

Input Text required Attribute

Input Text Object

Example

Check if a text field is filled out before submitting:

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

x output result is:

true

Definition and Usage

The required attribute is used to set or return whether the text field must be filled out before submitting the form.

This attribute reflects the HTML required attribute.


Browser Support

All major browsers support the required attribute, except Internet Explorer 9 and earlier versions and Safari.


Syntax

Return the required attribute:

Set the required attribute:

Attribute Values

Value Description
true|false Specifies whether the text field is a required part of form submission. true - The text field is a required part of form submission<br> false - Default. The text field is not a required part of form submission

| Return Value: | Boolean, returns 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;

Related Pages

HTML Reference: HTML <input> required Attribute


❮ Jsref Getutcmonth Dom Obj Legend ❯