Input DatetimeLocal autofocus Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime Local

Description

The autofocus property sets or gets whether a local datetime field should get focus when the page loads.

This property reflects the HTML autofocus attribute.

Set the autofocus property with the following Values

Value Description
true|false Sets whether a local datetime field should get focus when the page loads
  • true - The local datetime field gets focus
  • false - Default. The local datetime field does not get focus

Return Value

A Boolean, returns true if the local datetime field gets focus when the page loads, otherwise it returns false

The following code shows how to check if a local datetime field gets focus upon page load:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="datetime-local" id="myLocalDate" autofocus>

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

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

<script>
function myFunction() {//from w w w.  java 2 s  .c o  m
    var x = document.getElementById("myLocalDate").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

Related Tutorials