- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input Date required Property
The HTML DOM Input Date required property determines whether Input date is compulsory to set or not.
Syntax
Following is the syntax −
- Returning boolean value - true/false
inputDateObject.required
- Setting required to booleanValue
inputDateObject.required = booleanValue
Boolean Values
Here, “booleanValue” can be the following −
| booleanValue | Details |
|---|---|
| true | It defines that it is compulsory to set the date field to submit form. |
| false | It is the default value and to set date field is not compulsory. |
Example
Let us see an example of Input Date required property −
<!DOCTYPE html> <html> <head> <title>Input Date required</title> </head> <body> <form> <div> Name: <input type="text" name="fullName"> </div> <div> Date of Birth: <input type="date" id="dateSelect" required> </div> </form> <button onclick="submit()">Confirm</button> <div id="divDisplay"></div> <script> var divDisplay = document.getElementById("divDisplay"); var inputDate = document.getElementById("dateSelect"); function submit() { if(inputDate.required==true && inputDate.value==='') divDisplay.textContent = 'DOB required'; else divDisplay.textContent = 'Details Received'; } </script> </body> </html>
Output
This will produce the following output −
Clicking ‘Confirm’ button −

After clicking ‘Confirm’ button with value of date field set −

Advertisements