Javascript DOM HTML Input Week autofocus Property

Introduction

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

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

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

input elements with type="week" are not supported in Internet Explorer or Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="week" id="myWeek" autofocus>

<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from   ww w. ja  va  2s.co  m*/
  var x = document.getElementById("myWeek").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a week field should automatically get focus on page load.

This property mirrors the HTML autofocus attribute.

The <input type="week"> element is not supported in Firefox.

Property Values

Value Description
true The week field gets focus
falseDefault. The week field does not get focus

The autofocus property returns true if the week field automatically gets focus on page load, otherwise it returns false.




PreviousNext

Related