Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 27th, 2007, 10:35 AM
Authorized User
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default Calculate running total on form and prevent text

I am looking for help with an issue, basically I have an aspx form with 4 textboxes for entering in numeric values, I want the 5ht textbox to keep a running total ((txt 1+ txt2 )- (txt3 + txt4)), I also want to prevent the user for entering alphanumber text but I want each text box to have a default value of ‘0.00’ meaning the user cannot delete the decimal point.
I so far this workinb in that my page will calculate the totals based on the code behind below, this method gets called on the OnTextChanged="addFields" method of the textbox:
protected void addFields(object sender, EventArgs e)
        int TotalPlus;
        int TotalMinus;
        int TotalFinance;

        if (txt_Cust_deposit.Text.Trim().Length <= 0)
            txt_Cust_deposit.Text = "0";

        if (txt_Cash_Price.Text.Trim().Length <= 0)
            txt_Cash_Price.Text = "0";
        if (txt_Trade_in.Text.Trim().Length <= 0)
            txt_Trade_in.Text = "0";
        if (txt_Settlement.Text.Trim().Length <= 0)
            txt_Settlement.Text = "0";

        TotalMinus = Convert.ToInt32(txt_Cust_deposit.Text) +

        TotalPlus = Convert.ToInt32(txt_Cash_Price.Text) +

        TotalFinance = TotalPlus - TotalMinus;

        txt_Finace_amount.Text = TotalFinance.ToString();


I have added onkeyup as an attribute and called this client function from it :
function ValidateText(i)
    i.value = i.value.replace(/[^\d]+/g, '');

This does prevent text from being entered, but no longer calculates my total or allows me to enter a ‘.’.
Please help
Thank You

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate a running total Neal XSLT 3 March 22nd, 2007 11:16 AM
Calculate total hours based on Time deepcover1 Access 1 April 5th, 2006 01:50 AM
How To Calculate Monthy Total on-the-clock time Michaniker Access 2 December 2nd, 2005 06:06 PM
Running Total jdmorr SQL Language 5 March 9th, 2005 03:28 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.