Input Search required Attribute

Definition and Usage

required Set or return whether the search field must be filled out before submitting the form.

This property reflects the HTML required attribute.

See also:

HTML Reference Manual:HTML <input> required Attribute

Example

Example 1

Determine whether the search field must be filled out before submitting the form:

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

Try it yourself

Example 2

Set the search field as a required part of the form submission:

document.getElementById("mySearch").required = true;

Try it yourself

Syntax

Return the required attribute:

searchObject.required

Set the required attribute:

searchObject.required = true|false

Attribute value

Value Description
true|false

Specify whether the search field should be a required part of the form submission.

  • true - The search field is a required part of the form submission
  • false - Default. The search field is not a required part of the form submission.

Technical Details

Return value: Boolean value, if the search field is a required part of the form submission, it returns true; otherwise return false.

Browser Support

The numbers in the table indicate the first browser version to fully support this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support