Javascript Reference - HTML DOM Input Week value Property








The value attribute from the input week element specifies a week and year for the week field.

The value property sets or gets value attribute of a week field.

Browser Support

value Yes No No Yes Yes

Syntax

Return the value property.

var v = weekObject.value

Set the value property.

weekObject.value=YYYY-WWW




Property Values

Value Description
YYYY-WWW Specifies the week and year.
  • YYYY - year (e.g. 2011)
  • '-W' is the separator for week part
  • WW - week (in the range of 1 to 52 or 53, e.g. 01 for the first week of the year)
Example: 2014-W15

Return Value

A String type value representing the year and week of the week field.

Example

The following code shows how to get the week and year of a week field.


<!DOCTYPE html>
<html>
<body>
<input type="week" id="myWeek" value="1995-W35">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  w w w . ja  va2 s .c  o  m-->
    var x = document.getElementById("myWeek").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set the week and year for a week field.


<!DOCTYPE html>
<html>
<body>
Week and Year: <input type="week" id="myWeek">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  w w  w .  j  a  v a2s.  co  m-->
    document.getElementById("myWeek").value = "2014-W48";
}
</script>

</body>
</html>

The code above is rendered as follows: