Javascript DOM HTML Input Date autofocus Property get

Introduction

Find out if a date field automatically gets focus on page load:

var x = document.getElementById("myDate").autofocus;

Click the button to find out if the date field automatically gets focus on page load.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="date" id="myDate" autofocus>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from   w ww . ja v  a2s  . c  o  m
  var x = document.getElementById("myDate").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a date field can get focus on page load, or not.

This property mirrors the HTML autofocus attribute.

The autofocus property accepts and returns a boolean value.

Value Description
true The date field gets focus
false Default. The date field does not get focus



PreviousNext

Related