Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a javascript program to make a simple calculator

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which built-in method combines the text of two strings and returns a new string?

1081


What is difference between undefined variable and undeclared variable?

897


What is the use of blur function?

914


What is ‘this’ keyword in JavaScript?

943


How can a value be appended to an array?

912


What are undefined and undeclared variables?

927


What web sites do you feel use javascript most effectively (i.e., Best-in-class examples)? The worst?

906


Name the types of functions.

906


What is primitive data types in javascript?

940


Do you have to declare variables in javascript?

915


How many types of variables are there in javascript?

888


What is callback in javascript?

946


What is difference between local and global scope in javascript ?

986


What is the scope variable in javascript?

971


Can you explain the difference between == and ===?

1050