Input DatetimeLocal defaultValue Property - Javascript DOM HTML Element

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

Return Value

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:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<input type="datetime-local" id="myLocalDate" value="2018-11-16T15:25:33">

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

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;

Related Tutorials