Javascript Reference - HTML DOM Input DatetimeLocal Object








The Input DatetimeLocal object represents an HTML <input> element with type="datetime-local".

Input DatetimeLocal Object Properties

Property Description
autocomplete Sets or gets the autocomplete attribute of a local datetime field
autofocus Sets or gets whether a local datetime field can automatically get focus upon page load
defaultValue Sets or gets the default value of a local datetime field
disabled Endable or disable a local datetime field
form Get a reference to the form that contains the local datetime field
list Get the datalist that contains the local datetime field
max Sets or gets the max attribute of the local datetime field
min Sets or gets the min attribute of the local datetime field
name Sets or gets the name attribute of a local datetime field
readOnly Sets or gets whether the local datetime field is read-only
required Sets or gets whether the local datetime field must be filled before submitting a form
step Sets or gets the step attribute of the local datetime field
type Returns type of the local datetime field
value Sets or gets the value attribute of a local datetime field




Standard Properties and Events

The Input DatetimeLocal object supports the standard properties and events.

Example

We can access an <input> element with type="datetime-local" by using getElementById().


<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate" value="2014-12-16T12:25:33">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w  w  w. j  a  v a  2 s.co  m-->
<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create an <input> element with type="datetime-local" by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from  w w  w .jav a  2  s.com-->
    var x = document.createElement("INPUT");
    x.setAttribute("type", "datetime-local");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: