Table of Contents
show
Example 36
Write functions to add and subtract two numbers taken through html forms
<html>
<head>
<title> Form input </title>
</head>
<body>
<form name="forma">
Number 1 : <input type="text" name="tb1" id="tb1"> <br> <br>
Number 2 : <input type="text" name="tb2" id="tb2"> <br> <br>
<input type="button" value = "Addition" onclick="Add(document.forma.tb1.value, document.forma.tb2.value)">
<input type="button" value = "Subtraction" onclick="Sub(document.forma.tb1.value, document.forma.tb2.value)"> <br>
Result : <input type = "text" name = "tb3"> <br>
</form>
<script>
function Add(n1,n2)
{
n1 = parseFloat(n1);
n2 = parseFloat(n2);
document.forma.tb3.value = n1 + n2;
}
function Sub(n1,n2)
{
n1 = parseFloat(n1);
n2 = parseFloat(n2);
document.forma.tb3.value = n1 - n2
}
</script>
</body>
</html>
Output:
Views: 98