I attend a Javascript course and I have some exercises as homework. In one of them I have to create a Javascript function with the following role: when I press the button, the function should take the data from the first field of text and put it in the next 3 input fields (day, month and year).
I wrote the function, but it doesn't work. Can you tell me why? Thank you.
<!DOCTYPE html>
<html>
<head></head>
<body>
<input type="text" value="20/12/2015" />
<button onclick="calendar()">Push the button</button><br/>
<input type="text" placeholder="day" /><br />
<input type="text" placeholder="month" /><br />
<input type="text" placeholder="year" />
<script>
function calendar() {
var x = "20/12/2015";
var day = x.substring(0, 2);
var month = x.substring(3, 5);
var year = x.substring(6);
document.getElementsByTagName("input")[1].innerHTML = day;
document.getElementsByTagName("input")[2].innerHTML = month;
document.getElementsByTagName("input")[3].innerHTML = year;
}
</script>
</body>
</html>