i have couple textboxes on my form. Few expenses and a balance.
I use javascript to calculate the balance when the expense textboxes get changed like so:
$(document).ready(function () {
// add up main numbers
$("input[class*='add']").change(function (event) {
var sum = 0;
var subsum = 0;
var num = 0;
$("input[class*='add']").each(function (event) {
num = parseInt($(this).val()) || 0;
sum = sum + num;
});
$("input[class*='minus']").each(function (event) {
num = parseInt($(this).val()) || 0;
sum = sum - num;
});
$("input[class*='addcost']").each(function (event) {
num = parseInt($(this).val()) || 0;
subsum = subsum + num;
});
var balance = $("input[id*='txtBegBal']").val() - sum;
$("input[id*='txtEnding']").val(balance);
$("input[id*='txtTotalCost']").val(subsum);
});
the results show correct on screen, however when I click on "save", the txtTotalCost still shows the value, before javascript has updated it, so it does not get saved correctly.
could someone please point me in the right direction?
I do all my populating within the if (!Page.IsPostBack). The values that I change for "expenses" get passed in just fine, it's just the calculated field that is not.