Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display a running total?

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
0
0
US
This is probably incredibly simple, but I'm very new at this, and I not sure how to get this to work. What I want is for the box for the total to display a runnning total. The total should change as numbers are entered without having to hit "Submit". Obviously, this is a very simple example, but if I can get this one, I can get the the rest of it.
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
	<title>Untitled</title>
	<SCRIPT>
<!--
var x = 0;
var y = 0;
var SumXY = 0;
function calculate()
	{
     var SumXY = x + y; 
	}
//-->
</SCRIPT>
</head>

<body>

<FORM ACTION=&quot;#CGI.SCRIPT_NAME#&quot; METHOD=&quot;post&quot; NAME=&quot;MyForm&quot; ID=&quot;MyForm&quot;>
<B>VarX</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarX&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;x=VarX&quot;><BR>
<B>VarY</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarY&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;y=VarY&quot;><BR><BR>
<B>VarSum</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarSum&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;calculate()&quot;><BR>
</FORM>

</body>
</html>
Thank you very much! Calista :-X
Jedi Knight,
Champion of the Force
 
OK, folks, forgive me for thinking out loud. Here is my next attempt. It changes the total as I go along, but the total is wrong.
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
	<title>Untitled</title>
	<SCRIPT>
<!--
function calculate(which)
	{
     document.MyForm.VarSum.value = (document.MyForm.VarX.value + document.MyForm.VarY.value);
	 return; 
	}
//-->
</SCRIPT>
</head>

<body>

<FORM ACTION=&quot;#CGI.SCRIPT_NAME#&quot; METHOD=&quot;post&quot; NAME=&quot;MyForm&quot; ID=&quot;MyForm&quot;>
<B>VarX</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarX&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;calculate(this)&quot;><BR>
<B>VarY</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarY&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;calculate(this)&quot;><BR><BR>
<B>VarSum</B><BR>
<INPUT TYPE=&quot;text&quot; NAME=&quot;VarSum&quot; VALUE=&quot;0.00&quot; SIZE=&quot;5&quot; MAXLENGTH=&quot;5&quot; ONCHANGE=&quot;calculate(this)&quot;><BR>
</FORM>

</body>
</html>
I'll keep working on it! Calista :-X
Jedi Knight,
Champion of the Force
 
You might want to check this Javascript forum thread 216-103399 or 216-51991. These are two different approaches. This is were I learned how to do this.

Good Luck!:)
 
Calista,

I probably should have also given you the thread titles so that you can do a keyword search to find them. They are

&quot;Automatically adding tax to forms&quot; & &quot;Displaying textbox values elsewhere&quot; respectively.

Sorry...
Greg:~/

 
thread216-103399
tread216-51991
>>anyone: dont bother, just wanna check'em out.. ;-) regards, vic
 
oops, sorry again
thread216-51991
that way..
regards, vic
 
Perfect, vituz! 216-51991 was just the example I needed, especially since I am using Cold Fusion, too.

Thanks! I had tried a keyword search and didn't come up with that. Calista :-X
Jedi Knight,
Champion of the Force
 
it wasnt me, thunx 2 gbiskos

regards, vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top