Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


neethu
java script
1 Answer(s)      2 years and 11 months ago
Posted in : JavaScript Questions


write a java script code which provide a menu for user which will enable him/her to either add or subtract or multiply or divide two numbers and produce the corresponding result.


Advertisement
View Answers

October 3, 2011 at 12:32 PM


<html>
<script>
function add(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var res=Number(num1)+Number(num2);
alert("Result of addition is: "+res);
}
function subtract(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
if(num1>num2){
var res=Number(num1)-Number(num2);
alert("Result of subtraction is: "+res);
}
else{
var res=Number(num2)-Number(num1);
alert("Result of subtraction is: "+res);
}

}
function product(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var res=Number(num1)*Number(num2);
alert("Result of product is: "+res);
}

function divide(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var res=Number(num1)/Number(num2);
alert("Result of division is: "+res);
}
</script>
<form name="form">
<table>
<tr>
<td>Enter First Number:</td>
<td><input type="text" name="text1"></td>
</tr>
<tr>
<td>Enter Second Number:</td>
<td><input type="text" name="text2"></td>
</tr>
<tr>
<td><input type="button" value="Add" onclick="add();"></td>
<td><input type="button" value="Subtract" onclick="subtract();"></td>
</tr>
<tr>
<td><input type="button" value="Product" onclick="product();"></td>
<td><input type="button" value="Divide" onclick="divide();"></td>
</tr>
</table>
</html>


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com