$(document).ready(function() { $("#add").click(function() { var lastField = $("#buildyourform div:last"); var intId = (lastField && lastField.length && lastField.data("idx") + 1) || 1; var fieldWrapper = $("
"); fieldWrapper.data("idx", intId); var fName = $(""); var fType = $(""); var removeButton = $(""); removeButton.click(function() { $(this).parent().remove(); }); fieldWrapper.append(fName); fieldWrapper.append(fType); fieldWrapper.append(removeButton); $("#buildyourform").append(fieldWrapper); }); }); function save() { document.getElementById('formbuilder').submit(); }