Javascript Reference - HTML DOM Input Week Object








The Input Week object represents an HTML <input> element with type="week".

Input Week Object Properties

Property Description
autocomplete Sets or gets the autocomplete attribute of a week field
autofocus Sets or gets whether a week field should automatically get focus when the page loads
defaultValue Sets or gets the default value of a week field
disabled Sets or gets whether a week field is disabled, or not
form Get the form that contains the week field
list Get the datalist that contains the week field
max Sets or gets the max attribute of the week field
min Sets or gets the min attribute of the week field
name Sets or gets the name attribute of a week field
readOnly Sets or gets whether the week field is read-only
required Sets or gets whether the week field must be filled before submitting a form
step Sets or gets the step attribute of the week field
type Get the type of the week field
value Sets or gets the value attribute of a week field




Standard Properties and Events

The Input Week object supports the standard properties and events.

Example

We can access an <input> element with type="week" by using getElementById().


<!DOCTYPE html>
<html>
<body>
<input type="week" id="myWeek" value="2014-W15">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from   ww w .  j a  v  a 2 s  . c  o  m-->
<script>
function myFunction() {
    var x = document.getElementById("myWeek").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create an <input> element with type="week" by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--  w  w  w  . j  a  v  a  2s . com-->
    var x = document.createElement("INPUT");
    x.setAttribute("type", "week");
    x.setAttribute("value", "2014-W35");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: