Input Number required Property
Example
Check whether the number field is required before submitting the form:
var x = document.getElementById("myNumber").required;
x
The output is:
true
Try it »
Definition and Usage
The required property sets or returns whether the number field is a required field in the form.
This attribute reflects the HTML required attribute.
Browser support





All major browsers support the value attribute.
Note: Internet Explorer 9 and earlier versions do not support the HTML using the type="number" attribute .
Syntax
Return the required attribute:
numberObject
.required
Set the required attribute:
numberObject
.required=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Describes whether the number field is a required part before the form is submitted.
|
Technical Details
| Return Value: | A Boolean value: returns true if the number field is a required part of the form, otherwise returns false. |
|---|
More examples
Example
Set the number field as a required part of the form:
document.getElementById("myNumber").required = true;
Try it »
Related pages
HTML Reference Manual: HTML required attribute
Input Number Object