HTML DOM Input Search required Property
Example
Check if the search field is required before submitting the form:
var x = document.getElementById("mySearch").required;
x output result:
true
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
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.
|
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;
Related Pages
HTML Reference: HTML <input> required Attribute
YouTip