HTML | DOM Input Date required Property
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. It is false by default.
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 >w3wiki</ 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 >w3wiki</ 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 14.1
- Edge 12
- Firefox 57
- Google Chrome 20
- Opera 11
Contact Us