Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Number required Property

Input Number required Property

Input Number Object Reference Input Number Object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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.
  • true - The number field is a required part of the form
  • false - Default. The number field is an optional part of the form
  • |

    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 Reference Input Number Object