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