How to add additional form elements?

7b983cbdfad740a7bf883c9817a36940.png

The problem occurred when writing the code the "add contacts"
Tried using cloning, but when you click on this button, after 2 items are created from 2 additional.
Ask for help
July 8th 19 at 11:53
1 answer
July 8th 19 at 11:55
I did
$("body").on('click', '#ad', function() {
 a = a + 1;
 //put the attributes of the form fields to a variable
 var b = 'items[' + a + '][url]';
 var c = 'items[' + a + '][li_name]';
 var d = 'items[' + a + '][visible]';
 var e = 'items[' + a + '][veight]';
 //clone the div with fields
 $("#nav_field").clone().attr('id', 'nav_field_' + a).appendTo("#clon_place");
 //rewrite the attribute of the cloned fields
 $('#nav_field_' + a + ' select.url').attr("name", b);
 $('#nav_field_' + a + ' input.li_name').attr("name", c);
 $('#nav_field_' + a + ' input.visible').attr("name", d);
 $('#nav_field_' + a + ' select.veight').attr("name", e);
 });

Find more questions by tags HTMLJavaScriptjQuery