Input Search requiredProperty

Input Search 对象参考手册Input Search Object

Example

Check whether the search field is a required field before submitting the form:

var x = document.getElementById("mySearch").required;
xThe output result is:
true

Try it Yourself »

Definition and Usage

The required property is used to set or return whether the search field is a required field in a form.

This property reflects the HTML required attribute.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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


Syntax

Return the required property:

searchObject.required

Set the required property:

searchObject.required=true|false

Property Values

Value Description
true|false Describes whether the search field is a required part before the form is submitted.
  • 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 value, returns true if the search field is a required part of the form, otherwise 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 对象参考手册Input Search Object

Other Extensions