Javascript examples for DOM HTML Element:Input Datetime Local
The required property sets or gets whether a local datetime 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 local datetime field should be a required part of form submission. |
A Boolean, returns true if the local datetime field is a required part of form submission, otherwise it returns false
The following code shows how to check if a local datetime field must be filled out before submitting a form:
<!DOCTYPE html> <html> <body> <form action="#"> Date: <input type="datetime-local" id="myLocalDate" name="date"> <input type="submit"> </form>//from ww w. j ava 2 s . co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myLocalDate").required = true; var v = document.getElementById("myLocalDate").required; document.getElementById("demo").innerHTML = v; } </script> </body> </html>