Can anyone guide me how to dynamically add input field in a form and on save of the form, the same number of columns should get added to the corresponding table. Can we do it by using Hibernate or can only be done by JDBC?
$(document).ready(function () {
var counter = 1;
var favorite = [];
$('#add').click(function () {
var name = 'textName' + counter;
$('#inputContainer').append("<div>" + name + "<input type='text'
id='" + name + "' /></div>");
counter++;
});
$('#Save').click(function () {
for (var i = 1; i < counter; i++) {
var textValue = $('#textName' + i).val();
favorite.push(textValue);
//If you to save all data in one by one then Save function here
//Save(textValue);
}
//If you to save all data in one go then call Save function here
Save(favorite);
}); });
function Save(dataToSave)
{
$.ajax({
url: "AJAX_POST_URL",
type: "POST",
data: dataToSave,
success: function (data, textStatus, jqXHR) {
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}