I know this is probable a easy one for most of you...But this is my first Javascript. I am trying to write a code that will add two numbers entered by a user and calculate the sum. When I wrote the code inside the HTML it worked fine. But I have to use a .js file and call the function from there. And now my code does not work. Any guidance would be greatly appreciated. Here is the numbers.js file
function addNumbers()
{
var val1 = parseInt(document.getElementById("value1").value);
var val2 = parseInt(document.getElementById("value2").value);
var ansD = document.getElementById("answer");
ansD.value = val1 + val2;
}
ANd here is the HTML java3.html file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- hello.html
A simple addition example of XHTML/JavaScript
-->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Input tutorial</title>
<script type="text"/javascript" src="numbers.js"></script>
</head>
<body>
value1 = <input type="text" id="value1" name="value1" value="1"/>
value2 = <input type="text" id="value2" name="value2" value="2"/>
<input type="button" name="Sumbit" value="Click here" onclick="javascript:addNumbers()"/>
Answer = <input type="text" id="answer" name="answer" value=""/>
</body>
</html>