nexana
nexana

Reputation: 1166

How to map dynamic array of input fields

I have a form with a set of input fields:

<form>
 <div class="row">
     <input type="text" name="product[1]">
     <input type="text" name="qty[1]"> 
 </div>
</form>

I also add new rows dynamically to the DOM with jquery's clone() function.

What is the best way to increase the index number? Or is there a better way to 'map' the product and qty fields before submitting to a PHP script?

Upvotes: 1

Views: 1089

Answers (1)

Rodion
Rodion

Reputation: 521

Try this:

<form>
 <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
   <div class="row">
     <input type="text" name="product[]">
     <input type="text" name="qty[]"> 
 </div>
</form>

Upvotes: 1

Related Questions