Calculate running total on form and prevent text
Hi,
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) +
Convert.ToInt32(txt_Trade_in.Text);
TotalPlus = Convert.ToInt32(txt_Cash_Price.Text) +
Convert.ToInt32(txt_Settlement.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)
{
if(i.value.length>0)
{
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
|