Four Arithmetic Operation with the help of HTML & Javascript
<!DOCTYPE html>
<html>
<head>
<title>Four function calculators</title>
<script language="javascript">
function Addition()
{
var x,y,c,c1,z,sp, c2,c3;
x=parseInt(document.calculator.x.value);
y=parseInt(document.calculator.y.value);
c=document.getElementById("c");
c1=document.getElementById("c1");
sp=document.getElementById("sp");
c2=document.getElementById("c2");
c3=document.getElementById("c3");
if(c.checked==true)
{
z=x+y;
//alert(z);
sp.innerHTML=z;
c1.checked=false;
c2.checked=false;
c3.checked=false;
}
// body...
}
function Substraction()
{
var x,y,c,c1,z,sp,c2,c3;
x=parseInt(document.calculator.x.value);
y=parseInt(document.calculator.y.value);
c=document.getElementById("c");
c1=document.getElementById("c1");
sp=document.getElementById("sp");
c2=document.getElementById("c2");
c3=document.getElementById("c3");
if(c1.checked==true)
{
z=x-y;
//alert(z);
sp.innerHTML=z;
c.checked=false;
c2.checked=false;
c3.checked=false;
}
// body...
}
function multiplication()
{
var x,y,c,c1,z,sp,c2,c3;
x=parseInt(document.calculator.x.value);
y=parseInt(document.calculator.y.value);
c=document.getElementById("c");
c1=document.getElementById("c1");
sp=document.getElementById("sp");
c2=document.getElementById("c2");
c3=document.getElementById("c3");
if (c2.checked==true)
{
z=x*y;
//alert(z);
sp.innerHTML=z;
c.checked=false;
c1.checked=false;
c3.checked=false;
}
}
function division()
{
var x,y,c,c1,z,sp,c2,c3;
x=parseInt(document.calculator.x.value);
y=parseInt(document.calculator.y.value);
c=document.getElementById("c");
c1=document.getElementById("c1");
sp=document.getElementById("sp");
c2=document.getElementById("c2");
c3=document.getElementById("c3");
if (c3.checked==true)
{
z=x/y;
//alert(z);
sp.innerHTML=z;
c.checked=false;
c1.checked=false;
c2.checked=false;
}
}
</script>
</head>
<body>
<form name="calculator">
Enter first Number<input type="text" name="x"><br>
Enter second number<input type="text" name="y"><br>
Answer:<span id="sp"></span>
<input type="checkbox" name="c" id="c" value="add" onclick="Addition();">Add
<input type="checkbox" name="c1" id="c1" value="sub" onclick="Substraction();">Sub
<input type="checkbox" name="c2" id="c2" value="multiplication" onclick="multiplication();">multi
<input type="checkbox" name="c3" id="c3" value="division" onclick="division();">div
</body>
</html>
0 Comments:
Post a Comment
If you have any doubts . Please let me know.