Help with Cloning/Duplicating fields
So I have this code for cloning fields from a form to add another selection below. This part is working fine. However I am unsure of when adding the new fields, that each new field has it's own unique attributes instead of the ones that were clones. I think this may be due to the (var num = $('.clonedInput').length) portion of the script but I am unsure. I want to clone a form and have the attributes to things such as boxes and radio buttons selected unique.
Code:
<script type="text/javascript">
$(document).ready(function() {
$('#btnAdd').click(function() {
var num = $('.clonedInput').length;
var newNum = new Number(num + 1);
var newElem = $('#input' + num).clone().attr('', 'input' + newNum);
newElem.children(':first').attr('', 'name' + newNum).attr('name', 'name' + newNum);
$('#input' + num).after(newElem);
newElem.find('input,textarea').val('');
$('#btnDel').attr('disabled','');
});
$('#btnDel').click(function() {
var num = $('.clonedInput').length;
$('#input' + num).remove();
$('#btnAdd').attr('disabled','');
if (num-1 == 1)
$('#btnDel').attr('disabled','disabled');
});
$('#btnDel').attr('disabled','disabled');
});