<!DOCTYPE html>
<html>
<meta charset = "utf-8">
<head>
<title>Assignment 6</title>
<script type = "text/JavaScript">
function years()
{
var yourName = document.getElementById("name").value;
var yearBorn = document.getElementById("yearBorn").value;
var today = new Date();
var currentYear = today.getFullYear();
var age = currentYear - yearBorn;
if(age >= 0)
{
document.write("Hello, " +yourName+ ". You are " +age+ " years old.");
}
else
{
document.write("You are not born yet.");
}
document.close();
};
</script>
</head>
<body>
<form method = "post">
<p>Enter your name: <input type = "text" id = "name" size = "25" /></p>
<p>Enter year Born: <input type = "text" id = "yearBorn" size = "4" /></p>
<p><input type = "submit" value = "Click to show message" onClick = "years()" /></p>
</form>
</body>
</html>
Trying to get the javascript portion to display the messages when a user clicks the submit button. However, for me it just refreshes the page, and doesn't output any messages.