I've just started learning javascript and I'm having trouble with a homework problem. The problem gets user input via php (inputs are years to forecast, population, and growth rate). then the javascript should produce a table in the format of (years, population and change).
<!doctype html>
<META HTTPEQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta httpequiv="expires" content="0" />
<html lang="en">
<head>
<title> hw8 </title>
<link rel="stylesheet" href="hw8.css">
<script src="hw8.js"></script>
</head>
<body>
<form name="inputform">
<div id="input">
<h2> Population Growth </h2>
Years to forecast: <input type="text" value="<? print $_POST['years']; ?>" name="years"> <br/> <br/>
Current Population: <input type="text" value="<? print $_POST['population']; ?>" name="population"> <br/> <br/>
Growth Rate: <input type="text" value="<? print $_POST['rate']; ?>" name="rate"> <br/> <br/>
<div id="button"> <input type="submit" value="Calculate" id="calc"> </div>
</div>
</form>
<div id="tables">
<table id="table">
<tr>
<th> Year </th> <th> Population </th> <th> Change </th>
<tr>
<td> 2017 </td> <td> . </td> <td> . </td>
</tr>
</table>
</div>
</body>
</html>
window.addEventListener("load", link_events, false);
function link_events() {
document.getElementById("calc").onclick = calculate;
}
function calculate() {
var form = document.forms["inputform"];
var year = 2017;
var i;
var years = document.getElementById('years');
for (i=0; i < years.length; i++){
year[i]++
}
var
var change = parseFloat(form)["population"] * (parseFloat(form)["rate"]/100)