$(document).ready(function(){ $(".tabbed-section").each(function(idx, obj){ $(obj).find(".tabs a").each(function(tabIdx, tab){ $(tab).click(function(e){ $(obj).find("fieldset").hide(); $(obj).find("a.active").removeClass('active'); $(this).addClass('active'); $("#" + $(this).attr('rel')).show(); return false; }); }) }); $("#userOtherEmissionSequestrationsItem1CarbonPrice").bind("change", function(){if(!isNaN(this.value)){recalculateSeq();}}); $("#userOtherEmissionSequestrationsItem1TonnesCO2e").bind("change", function(){if(!isNaN(this.value)){recalculateSeq();}}); $("#userOtherEmissionSequestrationsItem2CarbonPrice").bind("change", function(){if(!isNaN(this.value)){recalculateSeq();}}); $("#userOtherEmissionSequestrationsItem2TonnesCO2e").bind("change", function(){if(!isNaN(this.value)){recalculateSeq();}}); forceNumeric("#userOtherEmissionSequestrationsItem1CarbonPrice"); forceNumeric("#userOtherEmissionSequestrationsItem2CarbonPrice"); forceNumeric("#userOtherEmissionSequestrationsItem1TonnesCO2e"); forceNumeric("#userOtherEmissionSequestrationsItem2TonnesCO2e"); }) function recalculateSeq() { pricetotal = 0; tonnestotal = 0; if (!isNaN($("#userOtherEmissionSequestrationsItem1CarbonPrice").val()) && !isNaN($("#userOtherEmissionSequestrationsItem1TonnesCO2e").val())) { pricetotal += parseFloat($("#userOtherEmissionSequestrationsItem1CarbonPrice").val()) * parseFloat($("#userOtherEmissionSequestrationsItem1TonnesCO2e").val()); tonnestotal += parseFloat($("#userOtherEmissionSequestrationsItem1TonnesCO2e").val()); $("#userOtherEmissionSequestrationsItem1").html("$"+pricetotal.toFixed(2)); } if (!isNaN($("#userOtherEmissionSequestrationsItem2CarbonPrice").val()) && !isNaN($("#userOtherEmissionSequestrationsItem2TonnesCO2e").val())) { price2 = parseFloat($("#userOtherEmissionSequestrationsItem2CarbonPrice").val()) * parseFloat($("#userOtherEmissionSequestrationsItem2TonnesCO2e").val()); pricetotal += price2; tonnestotal += parseFloat($("#userOtherEmissionSequestrationsItem2TonnesCO2e").val()); $("#userOtherEmissionSequestrationsItem2").html("$"+price2.toFixed(2)); } $("#otherTonnesCO2eTotal").html(tonnestotal.toFixed(2)); $("#otherTotalValue").html("$"+pricetotal.toFixed(2)); }