Reputation: 45
I have this code:
<script>
function getAge() {
var birthdate = document.getElementById("birthdatebox").value;
document.getElementById("agecomputed").innerHTML = calculateAge2(birthdate);
}
</script>
and
<input type="text" name="birthdatebox" />
<button onclick="getAge()" name="birthdatebutton">Get Your Age</button>
<div id="agecomputed"></div>
It should return the calculated value. Nothing happens. Just doesn't work. Please help.
UPDATE: I have a reference to the js file, which contains the calculateAge2 function and it does work when I pass a number directly instead of birthdate variable.
Upvotes: 0
Views: 410
Reputation: 5164
You need to add the id
attribute to your <input>
element, like this...
<input type="text" name="birthdatebox" id="birthdatebox" />
Upvotes: 1