0

This is the question, I have a form that contains a number (not always the same amount) of inputs. All that inputs are tagged by the name ("qtyv[]") and all have the same id ("qtyv").

I want to sum all the values of that inputs, but I dont know how to get that data with javascript.

Any ideas?

Qty 1= <input type="text" id="qtyv" name="qtyv[]" />
Qty 2= <input type="text" id="qtyv" name="qtyv[]" />

...

I want to sum the values of all that inputs...

AleOtero93
  • 473
  • 12
  • 32

1 Answers1

0

Solution: A loop...

var i = 0;
var qty = 0;
while (document.getElementsByName('qtyv[]')[i]){
qty += document.getElementsByName('qtyv[]')[i].value;
i++;
}

When i reach to the limit of inputs, that function will return undefined so the while will exit.

AleOtero93
  • 473
  • 12
  • 32