0
   

PLS HELP!!!! calculator in javascript and html

 
 
Reply Mon 14 Sep, 2009 07:07 am
i have written a code for calculator in html and javascript,
every button works well except that the final answer doesnt appear when "=" is clicked...pls help fast if any1 finds out the mistake......



<html>
<head>
<title>calculator</title>
<script language="JavaScript">
l=0;
m="";
n="";
function one()
{
var a= document.mine.one1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function two()
{
var a= document.mine.two1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function three()
{
var a= document.mine.three1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function four()
{
var a= document.mine.four1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function five()
{
var a= document.mine.five1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function six()
{
var a= document.mine.six1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function seven()
{
var a= document.mine.seven1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function eight()
{
var a= document.mine.eight1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function nine()
{
var a= document.mine.nine1.value;
document.mine.field.value=(document.mine.field.value) + a;
}
function ac()
{
document.mine.field.value="";
}

function sum()
{
m=document.mine.field.value;
document.mine.field.value="";
l=1;
}
function diff()
{
m=document.mine.field.value;
document.mine.field.value="";
l=2;
}
function mul()
{
m=document.mine.field.value;
document.mine.field.value="";
l=3;
}
function div()
{
m=document.mine.field.value;
document.mine.field.value="";
l=4;
}
function equal()
{
n=document.mine.field.value;
if(l==1)
(document.mine.field.value)=(parseInt(m)+parseInt(n));
if(l==2)
(document.mine.field.value)=(parseInt(m)-parseInt(n));
if(l==3)
(document.mine.field.value)=(parseInt(m)*parseInt(n));
if(l==4)
(document.mine.field.value)=(parseFloat(m)/parseFloat(n));


}
</script>
</head>
<body>
<form name="mine">
<input type="text" name="field" value=""><br>
<input type="button" name="one1" value="1" onClick="one();">     <input type="button" name="two1" value="2" onClick="two();">     <input type="button" name="three1" value="3" onClick="three();"><br>
<input type="button" name="four1" value="4" onClick="four();">     <input type="button" name="five1" value="5" onClick="five();">     <input type="button" name="six1" value="6" onClick="six();"><br>
<input type="button" name="seven1" value="7" onClick="seven();">     <input type="button" name="eight1" value="8" onClick="eight();">     <input type="button" name="nine1" value="9" onClick="nine();"><br>
<input type="button" name="ac1" value="AC" onclick="ac();">     <input type="button" name="equal1" value="=" onClick=equal();"><br>
<input type="button" name="sum1" value="+" onClick="sum();">     <input type="button" name="diff1" value="-" onClick="diff();"><br>
<input type="button" name="mul1" value="*" onClick="mul">     <input type="button" name="div1" value="/" onClick="div();">
</form>
</body>
</html>
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 2,322 • Replies: 0
No top replies

 
 

Related Topics

So I just joined Facebook.... - Discussion by DrewDad
YouTube Is Doomed - Discussion by Shapeless
Internet disinformation overload - Discussion by rosborne979
Participatory Democracy Online - Discussion by wandeljw
OpenDNS and net neutrality - Question by Butrflynet
Internet Explorer 8? - Question by Pitter
 
  1. Forums
  2. » PLS HELP!!!! calculator in javascript and html
Copyright © 2019 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 10/13/2019 at 09:46:51