Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Input Date required Property

  • Difficulty Level : Basic
  • Last Updated : 23 Jun, 2021

The Input Date required property is used for setting or returning whether a date field must be filled out before submitting a form. 
The HTML required attribute is used to reflect the Input Date required property.
Syntax: 
 

  • For returning the required property: 
     
dateObject.required
  • For setting the required property: 
     
 dateObject.required = true|false

Property Value: 
 

  • true|false : It is used to specify whether a date field should be a required part of a form submission or not.

Return Values: It returns a Boolean value which represents that the Input date field is required or not.  

Below program illustrates the Date required property :
Example 1: Finding out if a date field must be filled out before submitting a form or not. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>Input Date required Property in HTML</title>
    <style>
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Input Date required Property</h2>
    <br>
 
    <form action="/initials.php">
        Date of Birth:
        <input type="date" id="Test_Date" name="DOB" required>
        <input type="submit">
    </form>
 
     
 
<p>To find out if the date field must be filled out
      before submitting the form, double-click the "Check" button.</p>
 
 
 
    <button ondblclick="My_Date()">Check</button>
 
    <p id="test"></p>
 
 
 
    <script>
        function My_Date() {
            var d = document.getElementById("Test_Date").required;
            document.getElementById("test").innerHTML = d;
        }
    </script>
 
</body>
 
</html>
                                          

Output: 
 



After clicking the button:
 

Example 2: Below code set the date required property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>Input Date required Property in HTML</title>
    <style>
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Input Date required Property</h2>
    <br>
 
    <form action="/initials.php">
        Date of Birth:
        <input type="date" id="Test_Date" name="DOB" required>
        <input type="submit">
    </form>
 
     
 
<p>To set the date required propertydoutle-click the "set" button.</p>
 
 
 
    <button ondblclick="My_Date()">Set</button>
 
    <p id="test"></p>
 
 
 
    <script>
        function My_Date() {
            var d = document.getElementById("Test_Date").required = "false";
            document.getElementById("test").innerHTML = d;
        }
    </script>
 
</body>
 
</html>
                                          

Output:

After clicking the button:

Supported Web Browsers: 
 

  • Apple Safari
  • Internet Explorer
  • Firefox
  • Google Chrome
  • Opera

 

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :