HTML DOM Input Date autofocus Property


The HTML DOM Input Date autofocus property sets/returns whether Input Date is focused upon initial page load.

Syntax

Following is the syntax −

  • Returning boolean value - true/false
inputDateObject.autofocus
  • Setting autofocus to booleanValue
inputDateObject.autofocus = booleanValue

Boolean Value

Here, “booleanValue” can be the following −

booleanValueDetails
trueIt defines that input will be autofocused on page load.
falseIt is the default value and input is not autofocused.

Example

Let us see an example of Input Date autofocus property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input Date Autofocus</title>
</head>
<body>
Date Select: <input type="date" id="Date" autofocus>
<button onclick="removeAutoFocus()">Remove Auto Focus</button>
<div id="divDisplay"></div>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputDate = document.getElementById("Date");
   divDisplay.textContent = 'Autofocus: '+inputDate.autofocus function removeAutoFocus() {
      if(inputDate.autofocus == true){
         inputDate.autofocus = false;
         divDisplay.textContent = 'Autofocus: '+inputDate.autofocus
      }
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ’Remove Auto Focus’ button −

After clicking ‘Remove Auto Focus’ button −

Updated on: 30-Jul-2019

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements