0

I have an array of elements in a table like this:

<td><input type="number" min="0" name="value[]" value="22.00"  class="form-control"></td>

<td><input type="number" min="0" name="value[]" value="11.00"  class="form-control"></td>

I want to do some validation on these values when I submit.

How can I obtain all the elements with name="value[]"?

I tried $("[name='value[]']").val(); but this only gives me the first one.

Mick
  • 1,401
  • 4
  • 23
  • 40
  • 1
    Iterate `$("[name='value[]']")` object using `.each()` i.e. `$("[name='value[]']").each(function(i, el){ var v = $(el).val(); })` – Satpal Jan 10 '18 at 12:32

1 Answers1

1

You can do it in a loop like below

$("input [name='value[]']").each(function(index,val){
  console.log($(val).val());
});

You can see the output on the console.

Arun
  • 3,640
  • 7
  • 44
  • 87