Write a javascript program to make a simple calculator
Answers were Sorted based on User's Feedback
Answer / sara
<html>
<script type="text/javascript">
function abc1()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(1)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(1)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc2()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(2)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(2)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc3()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(3)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(3)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc4()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(4)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(4)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc5()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(5)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(5)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc6()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(6)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(6)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc7()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(7)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(7)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc8()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(8)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(8)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc9()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(9)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(9)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abc0()
{
if((document.tp.tk3.value)==1)
{
i=parseInt(0)
d=parseInt(document.tp.tk1.value)
d=(d*10)+i;
document.tp.tk1.value=d;
}
if((document.tp.tk3.value)==2)
{
i=parseInt(0)
d=parseInt(document.tp.tk2.value)
d=(d*10)+i;
document.tp.tk2.value=d;
}
}
function abcdiv()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(4)
document.tp.tk7.value=ad
}
function abcadd()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(1)
document.tp.tk7.value=ad
}
function abcsub()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(2)
document.tp.tk7.value=ad
}
function abcmul()
{
a=parseInt(2)
document.tp.tk3.value=a
ad=parseInt(3)
document.tp.tk7.value=ad
}
function abcreset()
{
a=parseInt(1)
document.tp.tk3.value=a
document.tp.tk1.value=0
document.tp.tk2.value=0
document.tp.tk4.value=0
document.tp.tk7.value=0
}
function abcanswer()
{
if((document.tp.tk7.value)==1)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)
+parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==2)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)-
parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==3)
{
document.tp.tk4.value=parseInt(document.tp.tk1.value)
*parseInt(document.tp.tk2.value)
}
if((document.tp.tk7.value)==4)
{
document.tp.tk4.value=parseInt
(document.tp.tk1.value)/parseInt(document.tp.tk2.value)
}
}
function abcnext()
{
a=parseInt(2)
document.tp.tk3.value=a
}
</script>
<h3 align="center">
<form name=tp>
<input type=text name=tk1 value="0"><br/>
<input type=text name=tk2 value="0"><br/>
<input type=text name=tk4 value="0"><br/>
<input type=hidden name=tk3 value="1"><br/>
<input type=hidden name=tk7 value="0"><br/>
<input type="button" onclick=abc1() value="1">
<input type="button" onclick=abc2() value="2">
<input type="button" onclick=abc3() value="3"><br/>
<input type="button" onclick=abc4() value="4">
<input type="button" onclick=abc5() value="5">
<input type="button" onclick=abc6() value="6"><br/>
<input type="button" onclick=abc7() value="7">
<input type="button" onclick=abc8() value="8">
<input type="button" onclick=abc9() value="9"><br/>
<input type="button" onclick=abc0() value="0"><br/>
<input type="button" onclick=abcadd() value="add">
<input type="button" onclick=abcsub() value="sub">
<input type="button" onclick=abcmul() value="mul">
<input type="button" onclick=abcdiv() value="div"><br/>
<input type="button" onclick=abcanswer() value="answer">
<input type="button" onclick=abcreset() value="reset">
</form>
</body>
</html>
Is This Answer Correct ? | 7 Yes | 16 No |
What is the difference between remove() and removeChild()?
What is event in javascript?
What are disadvantages of using javascript?
What is the role of break and continue statements?
What is variable typing in javascript?
What is a null variable in javascript?
How we can get the value of an element using javascript?
What is scope chain in javascript?
Is javascript becoming obsolete?
What web sites do you feel use javascript most effectively (i.e., Best-in-class examples)? The worst?
How do I start a javascript project?
Explain how can you submit a form using JavaScript?