The value
property sets or gets the value attribute of a month field.
The value
attribute sets a month and year for the month field.
value |
Yes | No | No | Yes | Yes |
Return the value property.
var v = monthObject.value
Set the value property.
monthObject.value=YYYY-MM
Value | Description |
---|---|
YYYY-MM | Set the month and year.
|
A String type value, representing the month and year of the month field.
The following code shows how to get the month and year of a month field.
<!DOCTYPE html>
<html>
<body>
Month and year: <input type="month" id="myMonth" value="2014-11">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w w w .j ava 2 s . co m-->
<script>
function myFunction() {
var x = document.getElementById("myMonth").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set the month and year for a month field.
<!DOCTYPE html>
<html>
<body>
Month and year: <input type="month" id="myMonth">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w w w . java 2 s . c o m-->
document.getElementById("myMonth").value = "2014-02";
}
</script>
</body>
</html>
The code above is rendered as follows: