Input Month required Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month


The required property sets or gets whether a month field must be filled out before submitting a form.

This property reflects the HTML required attribute.

Set the required property with the following Values

Value Description
true|false Sets whether a month field should be a required part of form submission.
  • true - The month field is required
  • false - Default. The month field is not required

Return Value

A Boolean, returns true if the month field is a required part of form submission, otherwise it returns false

The following code shows how to check if a month field must be filled out before submitting a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form action="#">
  Month: <input type="month" id="myMonth" name="bdaymonth">
  <input type="submit">
</form>/* w  w w  .j a va  2 s .  c  om*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var v = document.getElementById("myMonth").required;
    document.getElementById("demo").innerHTML = v;

Related Tutorials