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

Answers were Sorted based on User's Feedback



Write a javascript program to make a simple calculator..

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

Post New Answer

More JavaScript Interview Questions

Hello , I am using following java script to open new window in I.E,but i am facing an issue the new window hangs often while opening,when you move mouse it opens normally.Can any body help me why this is happening as i am unable to understand this issue?please please if any one know so kindly help me I am in real difficulty through this issue.Thanks 'if(window.clipboardData){clipboardData.setData("Text","' + a.PatID + '");}' + 'ordwindow= window.open ("' + @OrderDetailURL + '", "RXOrderDetail", "location=0,status=0,menubar=0,toolba r=0,scrollbars=1,resizable=1"); ordwindow.moveTo(parent.screenLeft,0);var x; x=new ActiveXObject("WScript.Shell");x.SendKeys("% "); x.SendKeys ("x"); //fcttest((sp_RX_ChangeOrderStatus ' + '''' + a.DocID + '''' + ', 1, ' + convert(varchar,@SessionID) + '));' As [W],

0 Answers  


What is an ECMAScript?

0 Answers  


What is event target in javascript?

0 Answers  


Give code Email Checking

3 Answers  


What is negative infinity?

2 Answers   CoKinetic, Satyam,


How to call a function in every x seconds in javascript?

0 Answers  


What is the use of dom?

0 Answers  


How can a value be appended to an array?

0 Answers  


Which keyword is used to print the text in the screen?

0 Answers  


What is the Difference between HTML and DHTML

15 Answers   TCS,


Write the point of difference between web-garden and a web-farm?

0 Answers  


Can I learn javascript without knowing java?

0 Answers  


Categories