more then one jquery calculate on same page
I need some help running two jquery.calculation on the same page, in my
example only the 2nd table is working, I have added the script 2x and have
renamed all the elements but it's not working.
When I remove the 2nd script the 1st one is working. When I add the 2nd
script the first one stops.
I understand that somehow these 2 scripts need to be combine but I really
do not know how.
Thank you.
Here is an example: jsfiddle example
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty_]").bind("change keyup", recalc);
$("[name^=aantal_]").bind("change keyup", recalc);
$("[name^=price_]").bind("change keyup", recalc);
$("[name^=bedrag_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total_item]").calc(
"((qty * price) + (aantal * bedrag))",
{
qty: $("[name^=qty_]"),
aantal: $("[name^=aantal_]"),
price: $("[id^=price_]"),
bedrag: $("[id^=bedrag_]")
},
function (s) {
return s.toFixed(2);
},
function ($this) {
var sum = $this.sum();
$("#subTotal").val( sum.toFixed(2) );
}
);
}
</script>
<script>
$(document).ready(function() {
$("#idPluginVersion").text($.Calculation.version);
$("[name^=qty2_]").bind("change keyup", recalc);
$("[name^=aantal2_]").bind("change keyup", recalc);
$("[name^=price2_]").bind("change keyup", recalc);
$("[name^=bedrag2_]").bind("change keyup", recalc);
recalc();
});
function recalc() {
$("[id^=total2_item]").calc(
"((qty2 * price2) + (aantal2 * bedrag2))",
{
qty2: $("[name^=qty2_]"),
aantal2: $("[name^=aantal2_]"),
price2: $("[id^=price2_]"),
bedrag2: $("[id^=bedrag2_]")
},
function (s) {
return s.toFixed(2);
},
);
}
</script>
No comments:
Post a Comment