I am trying to create a form in html/javascript where the user can input their date of birth and then a message is displayed stating "you are 'x' years old", using the data from their date of birth. However I am completely unsure of how to get this to work?
Here is the code I have currently:
HTML:
<input type="date" id="myBirthday" value="dd-mm-yyyy">
<button onclick="submitBirthday()">Submit</button>
JS:
function submitBirthday() {
var birthday = document.getElementById("myBirthday").value;
document.getElementById("displayBirthday").innerHTML = ("You are " + birthday + " years old.");
}
I realise this displays "you are 'dd-mm-yyyy' years old currently, but this is all I've been able to do.
Any help will be greatly appreciated! Thanks