Currently building a shipping calculator and attempting to add in a
section that checks every shopping cart item's quantity and then
multiplies that quantity by the weight of that item.
The HMTL consists of input fields similar to the example below:
<input type="hidden" name="quantity1" value="1" />
<input type="hidden" name="weight1" value="3.1" />
<input type="hidden" name="quantity2" value="3" />
<input type="hidden" name="weight2" value="2.1" />

The way I designed the following portion of my script is it finds all
input elements with a name containing quantity.
If it is equal to or greater than 2 it will first assign a variable
with the quantity value, then find the corresponding weight input
field and pull the weight value from that. Then it will multiply those
together and then change the weight value to the new one.

                $("input[name*='quantity']").each(function(i) {
                        if ((Number($(this).val())) >= 2) {
                        multiplier = (Number($(this).val()));
                        weight = Number($("input[name=('weight' + 
(i))]").val());
                        multipliedweight = (weight) * (multiplier);
                        $("input[name=('weight' + (i))]").val(multipliedweight);
                }
                });

The first part where it gets the multiplier works and returns correct
values. The second two parts return NaN. I'm assuming I have my syntax
incorrect on the weight variable.

Thanks for taking a look and I hope someone can point me in the right
direction!

Reply via email to