Hi there,
I am not very experienced with Javascript, and I am trying to create a function that will multiply two fields and place the result in a third field, within a Repeater area.
So I have a working Repeater Area with data loaded from array M[Name] and M[Price]. The other fields are M[Qty] (entered by the user) and M[LineTotal] (which I want to calculate). Field names in the repeater are:
M[{var:area_repeater1.key}][Name]
M[{var:area_repeater1.key}][Price]
M[{var:area_repeater1.key}][Qty]
M[{var:area_repeater1.key}][LineTotal]
When the user enters a Qty, I want the script to calculate a Line total by multiplying Price and Qty.
So I created a JS function like
I expect that my problem is in the syntax that references the array elements Qty and Price, but I can find no reference or example that shows how to do it.
Any assistance greatly appreciated as always.
Cheers
Tim
I am not very experienced with Javascript, and I am trying to create a function that will multiply two fields and place the result in a third field, within a Repeater area.
So I have a working Repeater Area with data loaded from array M[Name] and M[Price]. The other fields are M[Qty] (entered by the user) and M[LineTotal] (which I want to calculate). Field names in the repeater are:
M[{var:area_repeater1.key}][Name]
M[{var:area_repeater1.key}][Price]
M[{var:area_repeater1.key}][Qty]
M[{var:area_repeater1.key}][LineTotal]
When the user enters a Qty, I want the script to calculate a Line total by multiplying Price and Qty.
So I created a JS function like
function linetotal() {
var total = 0,
linetotal = 0
;
jQuery('input[name^="M"]').each(function() {
linetotal = $(this.Qty).val() * $(this.Price).val();
jQuery($(this.LineTotal).val(linetotal));
total += parseFloat($(this.LineTotal).val());
});
jQuery('input[name="total_field"]').val(total);
}
I expect that my problem is in the syntax that references the array elements Qty and Price, but I can find no reference or example that shows how to do it.
Any assistance greatly appreciated as always.
Cheers
Tim