<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
//function parameters do not have types?
function calculateAge(birthYear, currentYear)
{
var page = document.getElementById("content");
var content = page.innerHTML;
var age = currentYear-birthYear;
var stage;
if (age <18)
{
stage = "Teenager";
}
else if (age >= 18 || age <= 35)
{
stage = "Adult";
}
else
{
stage = "Mature Adult";
}
var outputMessage = "Your stage is: " + stage + ".\n" + "Your age is: " + age + ".";
page.insertBefore(outputMessage, page.firstChild);
}
// var input = document.getElementById('submit');
// input.addEventListener('click', calculateAge);
// var form = document.getElementById('input');
// form.onsubmit = function()
// {
// calculateAge ()
// }
var button = document.getElementById("submit");
button.onclick = function()
{
value1 = button.form.box1.value;
value2 = button.form.box2.value;
calculateAge(value1, value2);
}
</script>
</head>
<body>
<div class="basic">
<form id="input">
<p class="content">
<label> Birth Year: <input type="text" id="box1"></label> <br></br>
<label> Current Year: <input type="text" id="box2"></label> <br></br>
<input type="button" value="Calculate" id="submit" onclick="calculateAge(document.getElementById('box1').value, document.getElementById('box2'.value))"/>
</p>
</form>
</div>
</body>
</html>
I am new to html and js and i am just trying to make a simple page with 2 input boxes that send user input data to a method via button click which then processes the data and outputs a message above the form. I cant understand why I am getting like 3-4 null errors, everything looks like its defined, no spelling mistakes, no duplicate IDs, every tag has an opening and closing tag, ive spent HOURS looking for whats wrong, cant see what im missing.