The abolished example of the form where the script adds new fields and therefore they are all of the same class.
<div class="forma"> <div class="initials"> <input type="text" name="first"> <input type="text" name="last"> </div> <div class="initials"> <input type="text" name="first"> <input type="text" name="lastn"> </div> <div class="initials"> <input type="text" name="first"> <input type="text" name="last"> </div> </div>
How to extract this data for the subsequent $ ajax.post as an array
{forma:[{firts: #, last: #}, {first: #, last:#}]}
you first need to create an array, then find all the elements with the class .initials , create an object in it with the properties first & last and this object push into the array? And I get an array, but the elements in it are undefined
var forma = new Array(); var len = $('.initials').size() ; for (var i = 0; i < len; i++) { var data = new Object(); data.first = $('.initials input[name="first"]:eq(i)').val(); data.last = $('.initials input[name="last"]:eq(i)').val(); ingred.push(data); }; console.log(forma);