Skip to content
Related Articles

Related Articles

HTML | DOM Input DatetimeLocal required Property

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 09 Dec, 2021

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

  • For returning the require property 
     
datetimelocalObject.required
  • For setting the required property 
     
 datetimelocalObject.required = true|false 

Property Value: 
 

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

Return Values: It returns a boolean value that specify rhe local datetime field is required or not. 

Below program illustrates the DatetimeLocal required property :
Finding out if a datetimeLocal field must be filled out before submitting a form or not.  
 

html




<!DOCTYPE html>
<html>
  
<head>
    <title>Input DatetimeLocal 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 DatetimeLocal required Property</h2>
    <br>
  
    <form action="/initials.php">
        Date of Birth:
        <input type="datetime-local" id="Test_DatetimeLocal" name="DOB" required>
        <input type="submit">
    </form>
  
      
<p>To find out if the datetimeLocal field must be filled out
      before submitting the form, double-click the "Check" button.</p>
  
  
    <button ondblclick="My_DatetimeLocal()">Check</button>
  
    <p id="test"></p>
  
  
    <script>
        function My_DatetimeLocal() {
            var d = document.getElementById("Test_DatetimeLocal").required;
            document.getElementById("test").innerHTML = d;
        }
    </script>
  
</body>
  
</html>
                                          

Output: 
 

After clicking the button: 
 

Supported Web Browsers: 
 

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

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!