473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calculate Running sum of 4 text boxes on client side script?

I am wondering if it is possible to have a running total of four textboxes
so that when any text box is changed I could then calcuate the total of the
four boxes and show this on the webform.

Currenty I hvae four webform textboxes. I collect dollar abounts and want
to show the total as they change from box to box with some client side
script.

I then will insert these numbers with other text boxes into a database via
an insert statement.

Thanks,

Rog
Nov 18 '05 #1
2 4599
I do something like this. (It's probably not the most efficient, but it
works.) Each of the controls that will dynamically updating the total uses
the RegisterStartupScript, like so:

txtSubHalfDaysRate.Attributes.Add("onblur",
"javascript:calculateTotal(this.name);")

Anyway, onto the main function:

function calculateTotal(item)
{
if (item == "txtFirstHalfDayNumber" || item == "txtFirstHalfDayRate")
{
document.Form1.txtFirstHalfDaySum.value =
document.Form1.txtFirstHalfDayNumber.value *
document.Form1.txtFirstHalfDayRate.value;
calculateAllFields();
}
if (item == "txtFirstFullDayNumber" || item == "txtFirstFullDayRate")
{
document.Form1.txtFirstFullDaySum.value =
document.Form1.txtFirstFullDayNumber.value *
document.Form1.txtFirstFullDayRate.value;
calculateAllFields();
}
if (item == "txtSubHalfDaysNumber" || item == "txtSubHalfDaysRate")
{
document.Form1.txtSubHalfDaysSum.value =
document.Form1.txtSubHalfDaysNumber.value *
document.Form1.txtSubHalfDaysRate.value;
calculateAllFields();
}
if (item == "txtSubFullDaysNumber" || item == "txtSubFullDaysRate")
{
document.Form1.txtSubFullDaysSum.value =
document.Form1.txtSubFullDaysNumber.value *
document.Form1.txtSubFullDaysRate.value;
calculateAllFields();
}
if (item == "txtMiles" || item == "txtMilesRate")
{
//document.Form1.txtMilesSum.value = document.Form1.txtMiles.value *
document.Form1.txtMilesRate.value;
document.Form1.txtMilesSum.value =
Math.round((document.Form1.txtMiles.value *
document.Form1.txtMilesRate.value)*Math.pow(10,2))/Math.pow(10,2);
}
}
And here is the calculateAllFields function:

function calculateAllFields()
{
document.Form1.txtTotal.value =
parseFloat(document.Form1.txtFirstHalfDaySum.value ) +
parseFloat(document.Form1.txtFirstFullDaySum.value ) +
parseFloat(document.Form1.txtSubHalfDaysSum.value)
+ parseFloat(document.Form1.txtSubFullDaysSum.value) ;
}
"Davisro" <NA> wrote in message
news:#4**************@TK2MSFTNGP12.phx.gbl...
I am wondering if it is possible to have a running total of four textboxes
so that when any text box is changed I could then calcuate the total of the four boxes and show this on the webform.

Currenty I hvae four webform textboxes. I collect dollar abounts and want
to show the total as they change from box to box with some client side
script.

I then will insert these numbers with other text boxes into a database via
an insert statement.

Thanks,

Rog

Nov 18 '05 #2
Scott,

Thanks so much. This worked perfect. I have been looking for this kind of
stuff for a few days now.

Rog

"Scott Hamlin" <ad****@wunderhund.com> wrote in message
news:7d******************************@news.teranew s.com...
I do something like this. (It's probably not the most efficient, but it
works.) Each of the controls that will dynamically updating the total uses
the RegisterStartupScript, like so:

txtSubHalfDaysRate.Attributes.Add("onblur",
"javascript:calculateTotal(this.name);")

Anyway, onto the main function:

function calculateTotal(item)
{
if (item == "txtFirstHalfDayNumber" || item == "txtFirstHalfDayRate")
{
document.Form1.txtFirstHalfDaySum.value =
document.Form1.txtFirstHalfDayNumber.value *
document.Form1.txtFirstHalfDayRate.value;
calculateAllFields();
}
if (item == "txtFirstFullDayNumber" || item == "txtFirstFullDayRate")
{
document.Form1.txtFirstFullDaySum.value =
document.Form1.txtFirstFullDayNumber.value *
document.Form1.txtFirstFullDayRate.value;
calculateAllFields();
}
if (item == "txtSubHalfDaysNumber" || item == "txtSubHalfDaysRate")
{
document.Form1.txtSubHalfDaysSum.value =
document.Form1.txtSubHalfDaysNumber.value *
document.Form1.txtSubHalfDaysRate.value;
calculateAllFields();
}
if (item == "txtSubFullDaysNumber" || item == "txtSubFullDaysRate")
{
document.Form1.txtSubFullDaysSum.value =
document.Form1.txtSubFullDaysNumber.value *
document.Form1.txtSubFullDaysRate.value;
calculateAllFields();
}
if (item == "txtMiles" || item == "txtMilesRate")
{
//document.Form1.txtMilesSum.value = document.Form1.txtMiles.value *
document.Form1.txtMilesRate.value;
document.Form1.txtMilesSum.value =
Math.round((document.Form1.txtMiles.value *
document.Form1.txtMilesRate.value)*Math.pow(10,2))/Math.pow(10,2);
}
}
And here is the calculateAllFields function:

function calculateAllFields()
{
document.Form1.txtTotal.value =
parseFloat(document.Form1.txtFirstHalfDaySum.value ) +
parseFloat(document.Form1.txtFirstFullDaySum.value ) +
parseFloat(document.Form1.txtSubHalfDaysSum.value)
+ parseFloat(document.Form1.txtSubFullDaysSum.value) ;
}
"Davisro" <NA> wrote in message
news:#4**************@TK2MSFTNGP12.phx.gbl...
I am wondering if it is possible to have a running total of four textboxes so that when any text box is changed I could then calcuate the total of

the
four boxes and show this on the webform.

Currenty I hvae four webform textboxes. I collect dollar abounts and want to show the total as they change from box to box with some client side
script.

I then will insert these numbers with other text boxes into a database via an insert statement.

Thanks,

Rog


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
4
by: Coleen | last post by:
Please see threads on "Dumb question about Message boxes" - I went to the specified link - this works great if all you want to do is display a message box before any of your script behind the...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
2
by: Davisro | last post by:
I am wondering if it is possible to have a running total of four textboxes so that when any text box is changed I could then calcuate the total of the four boxes and show this on the webform. ...
1
by: Joel Barsotti | last post by:
Is there anything builtin to ASP.net that allows you to tie a text box to a button so when you press enter in the text box it emulates clicking a near by button. I've coded up some client side...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
14
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So,...
3
by: coolguyraj | last post by:
I have a javascript code to take value from two text boxes and calculate on triggering the "OnBlur" function and display in the third box. The code works fine with one line item,If i have more...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.