YouTip LogoYouTip

Prop Search Required

HTML DOM Input Search required Property

HTML DOM Input Search required Property

Input Search Object Reference Input Search Object

Example

Check if the search field is required before submitting the form:

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

x output result:

true

Try it yourself Β»


Definition and Usage

The required property is used to set or return whether a search field must be filled out before submitting a form.

This property reflects the HTML required attribute.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

The required property is supported in all major browsers, except Internet Explorer 9 and earlier, and Safari.


Syntax

Return the required property:

searchObject.required

Set the required property:

searchObject.required=true|false

Property Values

Value Description
true|false Specifies whether the search field must be filled out before submitting the form.
  • true - The search field is a required part of the form.
  • false - Default. The search field is an optional part of the form.

Technical Details

Return Value: A Boolean. Returns true if the search field is a required part of the form, otherwise it returns false.

More Examples

Example

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

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

Try it yourself Β»


Related Pages

HTML Reference: HTML <input> required Attribute


Input Search Object Reference Input Search Object

← Prop Search SizeProp Search Name β†’