Here's my setup so far: Fiddle
Whenever I click on the "Submit" button I need it to send an email to that specific person/email address.
But they all have the same names because I just cloned them. How do I dynamically give fields unique names and/or classes so I can email them separately?
$('.sub_container').first().clone(true).appendTo('.container').find('input').val('');
Also, since I will be dynamically adding new persons/email addresses, this must all happen on the same page. So I was thinking of using json or ajax perhaps?
Thanks in advance!
You can try some thign like this
Add Hidden field for counter
<input type='hidden' id='counter' value ='0' />
changes to click event
$('.add_new').click(function (e) {
var count = parseInt($("#counter").val(),10);
$("#counter").val(count+1);
var cloneEle = $(this).prev(".sub_container").clone(true);
cloneEle.attr("class","sub_container"+count)
cloneEle.find("input[type='text']").val('');
cloneEle.find('input[type="submit"]').val("Submit");
cloneEle.find('input[type="submit"]').attr("id","btnSubmit"+count)
cloneEle.appendTo('.container');
$('.preview_message').last().html('');
$('.preview_name').last().html('');
});