calculator making in Java script

This is a discussion on "calculator making in Java script" within the JavaScript Forum section. This forum, and the thread "calculator making in Java script are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 1st, 2005, 14:53
Junior Member
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
calculator making in Java script

hi

m new to Java Scritp

I have to make a calculator in JS.then how to make buttons like 1-9

thankx
Reply With Quote

  #2 (permalink)  
Old Oct 1st, 2005, 19:17
Banned Member
Join Date: Sep 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
<html>
<body>
c:\web\kalkulat.htm Saturdae, 01 Oct 05 at 1415
<! ************************ html ********************>
<div style="position:relative;left:0;top:-10px;">
<style> .senter1{text-align:center;vertical-align:middle;
font-family:sans-serif,helvetica,arial,lucida console;
border:solid 1px black;margin:0;padding:1px;
font-size:14px;line-height:15px;font-weight:700}</style>
<! *************** input form>
<form name="inputf">
<table cols=3 border=1 bgcolor="#ffccbb" margin=0>
<!******1>
<tr>
<td><input type=text name="digit1" value="1" size=2 class="senter1"
onClick="adddigit('1')"></td>
<td><input type=text name="digit2" value="2" size=2 class="senter1"
onClick="adddigit('2')"></td>
<td><input type=text name="digit3" value="3" size=2 class="senter1"
onClick="adddigit('3')"></td>
</tr>
<!******2>
<tr>
<td><input type=text name="digit4" value="4" size=2 class="senter1"
onClick="adddigit('4')"></td>
<td><input type=text name="digit5" value="5" size=2 class="senter1"
onClick="adddigit('5')"></td>
<td><input type=text name="digit6" value="6" size=2 class="senter1"
onClick="adddigit('6')"></td>
</tr>
<!******3>
<tr>
<td><input type=text name="digit7" value="7" size=2 class="senter1"
onClick="adddigit('7')"></td>
<td><input type=text name="digit8" value="8" size=2 class="senter1"
onClick="adddigit('8')"></td>
<td><input type=text name="digit9" value="9" size=2 class="senter1"
onClick="adddigit('9')"></td>
</tr>
<!****** 1=submit>
<tr>
<td><input type=text name="digit0" value="0" size=2 class="senter1"
onClick="adddigit('0')"></td>
<td colspan=2>
<input type=text value="calculate" size=8
style="cursorointer;cursor:hand;border:3px solid red"
style="background-color:#8dcff4" align="center"
onClick="dumath(document.inputf)"></td>
</tr>
</table>
</form>
</body>
</html>
Reply With Quote
  #3 (permalink)  
Old Oct 2nd, 2005, 16:42
Junior Member
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Thankx for the reply

where is its functionality?? n where is the body of "adddigit" fun??or atleast tell me wht this function is doing??n i want thta whenever i click on any button it shows it in the textbox
Reply With Quote
  #4 (permalink)  
Old Oct 3rd, 2005, 11:55
Banned Member
Join Date: Sep 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
<script language="JavaScript">
<!-- ***************** javaskript **************
//********** global variabels
var savestuff="";
//**
//*******************
function adddigit(kaller){
savestuff=savestuff+kaller;
document.inputf.anser.value=" ";
return}
//**
//*******************
function dumath(kaller){
if(savestuff == ""){
document.inputf.anser.value=" ";
return true}
anser =eval(savestuff);
werkstring=savestuff+"="+anser;
document.inputf.anser.value=werkstring;
savestuff="";
return}
// -->
</script>
Reply With Quote
  #5 (permalink)  
Old Oct 9th, 2005, 14:33
Junior Member
Join Date: Sep 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
urgent help req...

Plz Check this code n tell me is it rite approach...

<html>
<head>
<title> Java Script Practice </title>
<script language="JavaScript">

var savestuff="";

var stack="";
function adddigit(kaller){
if(kaller=='+')
{
op=kaller;

document.My.first.value="";
stack=eval(stack+'+'+savestuff);

document.My.first.value=stack;
savestuff=0;
}

else if(kaller=='*')
{
op=kaller;
if(stack=="")
{
stack=1;
document.My.first.value="";
stack=eval(stack+'*'+savestuff);

document.My.first.value=stack;

savestuff=0;
}
else
{

document.My.first.value="";
stack=eval(stack+'*'+savestuff);

document.My.first.value=stack;

savestuff=0;

}
}

else if(kaller=="=")


{
dumath(stack,savestuff,op);

}

else

{
savestuff=savestuff+kaller;
document.My.first.value=savestuff;

}


return

}


function dumath(f,sec,opt)
{

if(opt=="+")
{
anser=eval(f+'+'+sec);
document.My.first.value=anser;
}

else if(opt=="*")
{
anser=eval(f+'*'+sec);
document.My.first.value=anser;
}

return;

}



</script>
</head>
<body>

<form name="My">
<input type="text" name="first">

<table border="2" align=Center bgcolor="Blue">
<tr>
<td>

<input type="button" size="40" value="1" name="b1" onclick="adddigit('1')">
<input type="button" size="40" value="2" name="b2" onclick="adddigit('2')">
<input type="button" size="40" value="3" name="b3" onclick="adddigit('3')">

</td>
<tr>
<td>

<input type="button" size="40" value="4" name="b4" onclick="adddigit('4')">
<input type="button" size="40" value="5" onclick="adddigit('5')">
<input type="button" size="40" value="6" onclick="adddigit('6')">
</td>

</tr>


<tr>
<td>

<input type="button" size="40" value="7" onclick="adddigit('7')">
<input type="button" size="40" value="8" onclick="adddigit('8')">
<input type="button" size="40" value="9" onclick="adddigit('9')">
</td>
</tr>


<tr>
<td>
<input type="button" size="40" value="+" onclick="adddigit(value)">
<input type="button" size="40" value="=" onclick="adddigit(value)">
<input type="button" size="40" value="*" onclick="adddigit(value)">
</tr>
</tr>


</form>
</body>
</html>

m having some problems in it...when i entered sec. no it displays a leading zero wid it which is the value of var.."stack"..bt if I don't initialize it then eval function perform string concatination..

Its not a complete calculater only performing add n mul operations till noww
reply sooon
Reply With Quote
Reply

Tags
calculator, making, java, script

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with java script Pss JavaScript Forum 3 Mar 28th, 2008 21:17
I want ecards Java Script code. Anybody help 2 me. naagoo JavaScript Forum 1 Oct 28th, 2006 14:47
hi icon generator in Java Script srikanth JavaScript Forum 1 Sep 7th, 2006 17:24
Java Script HELP!!!! dandaman2006 JavaScript Forum 1 May 22nd, 2006 10:07
Not sure this is a java script question? haans_gruber JavaScript Forum 7 Sep 3rd, 2005 01:56


All times are GMT. The time now is 23:56.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43