$(document).ready(function(){ forceNumeric("#agistment"); forceNumeric("#contract_farming"); forceNumeric("#contract_harvesting"); forceNumeric("#other_farm_income"); forceNumeric("#wages_permanent"); forceNumeric("#wages_casual"); forceNumeric("#office_admin"); forceNumeric("#rates"); forceNumeric("#insurance"); forceNumeric("#accounting"); forceNumeric("#repairs"); forceNumeric("#water"); forceNumeric("#pasture"); forceNumeric("#electricity"); forceNumeric("#gas"); forceNumeric("#heating"); forceNumeric("#fuel"); forceNumeric("#lpg"); forceNumeric("#misc_1_value"); forceNumeric("#misc_2_value"); forceNumeric("#misc_3_value"); //recalculateTotal(); $("#misc_1_value,#misc_2_value,#misc_3_value,#lpg,#fuel,#heating,#gas,#electricity,#pasture,#water,#repairs,#agistment,#contract_farming,#contract_harvesting,#other_farm_income,#wages_permanent,#wages_casual,#office_admin,#rates,#insurance,#accounting").bind("change", function(){ recalculateTotal(); }); }); function recalculateTotal(){ total_income=0; total_over=0; total_income+= (isNaN(parseFloat($("#agistment").val()))) ? 0 : parseFloat($("#agistment").val()) ; total_income+= (isNaN(parseFloat($("#contract_farming").val()))) ? 0 : parseFloat($("#contract_farming").val()) ; total_income+= (isNaN(parseFloat($("#contract_harvesting").val()))) ? 0 : parseFloat($("#contract_harvesting").val()) ; total_income+= (isNaN(parseFloat($("#other_farm_income").val()))) ? 0 : parseFloat($("#other_farm_income").val()) ; $("#total_other_income").html(number_format(total_income)); total_over+= (isNaN(parseFloat($("#wages_permanent").val()))) ? 0 : parseFloat($("#wages_permanent").val()) ; total_over+= (isNaN(parseFloat($("#wages_casual").val()))) ? 0 : parseFloat($("#wages_casual").val()) ; total_over+= (isNaN(parseFloat($("#office_admin").val()))) ? 0 : parseFloat($("#office_admin").val()) ; total_over+= (isNaN(parseFloat($("#rates").val()))) ? 0 : parseFloat($("#rates").val()) ; total_over+= (isNaN(parseFloat($("#insurance").val()))) ? 0 : parseFloat($("#insurance").val()) ; total_over+= (isNaN(parseFloat($("#accounting").val()))) ? 0 : parseFloat($("#accounting").val()) ; total_over+= (isNaN(parseFloat($("#repairs").val()))) ? 0 : parseFloat($("#repairs").val()) ; total_over+= (isNaN(parseFloat($("#water").val()))) ? 0 : parseFloat($("#water").val()) ; total_over+= (isNaN(parseFloat($("#pasture").val()))) ? 0 : parseFloat($("#pasture").val()) ; total_over+= (isNaN(parseFloat($("#electricity").val()))) ? 0 : parseFloat($("#electricity").val()) ; total_over+= (isNaN(parseFloat($("#gas").val()))) ? 0 : parseFloat($("#gas").val()) ; total_over+= (isNaN(parseFloat($("#heating").val()))) ? 0 : parseFloat($("#heating").val()) ; total_over+= (isNaN(parseFloat($("#fuel").val()))) ? 0 : parseFloat($("#fuel").val()) ; total_over+= (isNaN(parseFloat($("#lpg").val()))) ? 0 : parseFloat($("#lpg").val()) ; total_over+= (isNaN(parseFloat($("#misc_1_value").val()))) ? 0 : parseFloat($("#misc_1_value").val()) ; total_over+= (isNaN(parseFloat($("#misc_2_value").val()))) ? 0 : parseFloat($("#misc_2_value").val()) ; total_over+= (isNaN(parseFloat($("#misc_3_value").val()))) ? 0 : parseFloat($("#misc_3_value").val()) ; $("#total_over").html(number_format(total_over)); }