HTML DOM Input FileUpload autofocus Property



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

Syntax

Following is the syntax βˆ’

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

Boolean Values

Here, β€œbooleanValue” can be the following βˆ’

booleanValue Details
true It defines that input will be autofocused on page load.
false It is the default value and input is not autofocused.

Example

Let us see an example of Input FileUpload autofocus property βˆ’

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Input FileUpload autofocus</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"]{
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>FileUpload-autofocus</legend>
<label for="FileSelect">Upload:
<input type="file" id="FileSelect" autofocus>
</label><br>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputFile = document.getElementById("FileSelect");
   divDisplay.textContent = 'Auto Focus:'inputFile.autofocus;
   function removeAutofocus() {
      inputFile.autofocus = false;
      divDisplay.textContent = 'Auto Focus:'inputFile.autofocus;
   }
</script>
</body>
</html>

Output

This will produce the following output βˆ’

Before clicking ’Remove Autofocus’ button βˆ’

After clicking β€˜Remove Autofocus’ button βˆ’

Updated on: 2019-07-30T22:30:26+05:30

113 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements