473,395 Members | 1,629 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,395 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 4602
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.