Page 1 of 1

calculations

Posted: 2020-02-06 19:16
by bescott53
Hi board, I have looked at the course and came up with this for calculation a total

Code: Select all

$j('#TravelAndSubsitence, #PoCost, #ForecastFees').change(function(){
                var TravelAndSubsitence = parseFloat($j('#TravelAndSubsitence').val() || 0;
                var PoCost = parseFloat($j('#PoCost').val() || 0;
                var ForecastFees = parseFloat($j('#ForecastFees').val() || 0;
                
                var training_expense_cost = (TravelAndSubsitence + PoCost + ForecastFees);
                $j('#training_expense_cost').val(training_expense_cost);
});
but its not working, any ideas. i am putting this inside the magic hook file

Re: calculations

Posted: 2020-02-08 00:45
by jsetzer
Hi,

what exactly is not working? Are there any console errors? Are you sure the event fires?


I highly recommend adding some logging and checking the values by using console.log(...) a lot like this:

Code: Select all

$j('#TravelAndSubsitence, #PoCost, #ForecastFees').change(function(){

console.log("field change event handler");

                var TravelAndSubsitence = parseFloat($j('#TravelAndSubsitence').val() || 0;
console.log('TravelAndSubsitence:' + TravelAndSubsitence);

                var PoCost = parseFloat($j('#PoCost').val() || 0;
console.log('PoCost:' + PoCost);

                var ForecastFees = parseFloat($j('#ForecastFees').val() || 0;
console.log('ForecastFees:' + ForecastFees);

                var training_expense_cost = (TravelAndSubsitence + PoCost + ForecastFees);
console.log('training_expense_cost:' + training_expense_cost);

console.log('before:' + $j('#training_expense_cost').val());
                $j('#training_expense_cost').val(training_expense_cost);
console.log('after:' + $j('#training_expense_cost').val());

console.log('/field change');
});
Then watch the console output for any errors or warnings and for the logged values.

Hope this helps!
Jan