I am trying to add these two numbers for an hour and can't get the result in the third text field. Please help me achieve this. thank you. also please tell me is there any add() method in javascript?
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style type="text/css">
#cal{
border:3px solid green;
padding: 5px;
width:250px;
text-align: center;
}
</style>
</head>
<body>
<button onclick="add()" id="button">Add</button>
<div id="cal">
<input type="text" value=" " id="num1" size="5">
+
<input type="text" value=" " id="num2" size="5">
=
<input type="text" value=" " id="sum" size="5">
</div>
<script>
function add()
{
var a = document.getElementById("num1").value;
var b = document.getElementById("num2").value;
var ans = a + b ;
document.getElementById("sum").value = ans;
}
</script>
</body>
</html>
typical JavaScript beginner problem. Don't worry, every JS developer had this problem once.