Hi I have this jQuery Function to duplicate form fields. Now I need to process them with PHP and my problem is that the cloned elements have the same input name.
I would like to add and variabel on the end of the name like _1 _2 _3 and so on. Also it would be great to put in a hidden field the amount of cloned elements to process them in a loop.
I'm really not good in jQuery and need it pretty quick otherwise I would start reading documentary about it and do it myself.
Maybe u guys can help me out. Would appriciate it a lot :)
There is the jQuery Part:
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedInput').length;
var newNum = new Number(num + 1);
var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
$('#input' + num).after(newElem);
$('#btnDel').removeAttr('disabled');
if (newNum == 10)// Max
$('#btnAdd').attr('disabled','disabled');
});
$('#btnDel').click(function() {
var num = $('.clonedInput').length;
$('#input' + num).remove();
$('#btnAdd').removeAttr('disabled','');
if (num-1 == 1)
$('#btnDel').attr('disabled','disabled');
});
$('#btnDel').attr('disabled','disabled');
});
And here the HTML
<div id="input1" class="clonedInput">
<!-- Elements to clone -->
<div class="control-group">
<label class="control-label" for="">Firmenname</label>
<div class="controls">
<input type="text" class="input-xlarge {validate:{required:true}}" rel="popover" data-content="Der Firmenname ist ein wichtiger Hinweis." data-original-title="Hilfe" id="firma" name="firma">
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Branche</label>
<div class="controls">
<input type="text" class="input-xlarge" name="branche">
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Anschrift</label>
<div class="controls">
<input type="text" class="input-xlarge" name="anschrift">
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Ansprechpartner</label>
<div class="controls">
<input type="text" class="input-xlarge" name="ansprechpartner">
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Tel.</label>
<div class="controls">
<input type="text" class="input-xlarge">
</div>
</div>
<!-- END Elements to clone -->
</div>