My HTML "sum.html" file seems not work with my "mathbox.js" file. I have declare it in the HTML head, however, when checking in Chrome console the num1 and num2 seems to work along with the sum by putting it sum = num1 + num2.
This is my Javascript function;
var num1 = Number(num1);
var num1 = Number(num1);
function calSum(){
var num1 = document.getElementById("num1").innerHTML;
var num2 = document.getElementById("num2").innerHTML;
var add = num1 + num2;
document.getElementById("sum").inneHTML = add;
}
Below is my HTML
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Matchbox</title>
<script type ="text/javascript" src="mathbox.js"></script>
</head>
<body>
<div>
<table border="1">
<tr>
<td style="text-align:right">First number:</td>
<td>
<input type="text" id = "num1" />
</td>
<td rowspan="2">
<input type="button" value="Calculate" onclick="calSum()">
</td>
</tr>
<tr>
<td style="text-align:right">Second number:</td>
<td>
<input type="text" id ="num2" />
</td>
</tr>
</table>
<br>
<table border="1">
<tr>
<td style="text-align:right">Sum:</td>
<td style="width:100px"> <input type="text" id ="sum" onclick="cal" /></td>
</tr>
</table>
</div>
</body></html>