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