Javascript examples for DOM HTML Element:Input Datetime Local
The defaultValue property sets or gets the default value of a local datetime field, which is the value specified in the HTML value attribute.
You can use defaultValue property to find out whether the local datetime field have been changed.
Set the defaultValue property with the following Values
Value | Description |
---|---|
value | Sets the default value of the local datetime field |
A String, representing the default value of the local datetime field
The following code shows how to change the default value of a datetime field:
<!DOCTYPE html> <html> <body> <input type="datetime-local" id="myLocalDate" value="2018-11-16T15:25:33"> <button type="button" onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from ww w .jav a 2 s .c o m*/ var x = document.getElementById("myLocalDate"); var defaultVal = x.defaultValue; var currentVal = x.value; if (defaultVal == currentVal) { document.getElementById("demo").innerHTML = "Default value and current value is the same: " + x.defaultValue + " and " + x.value; } else { document.getElementById("demo").innerHTML = "The default value was: " + defaultVal + "<br>current value is: " + currentVal; } } </script> </body> </html>