I have used this example http://jsfiddle.net/aaki/hMJEy/1/ to dynamically add input fields to a form, this works like a charm.
This is the code :
Javascript:
$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function(e) {
$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
});
$('.multi-field .remove-field', $wrapper).click(function() {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});
HTML:
<form role="form" action="/wohoo" method="POST">
<label>Stuff</label>
<div class="multi-field-wrapper">
<div class="multi-fields">
<div class="multi-field">
<input type="text" name="stuff[]">
<button type="button" class="remove-field">Remove</button>
</div>
</div>
<button type="button" class="add-field">Add field</button>
</div>
</form>
But now I want to get the data from the database and have the values put into the form. So that the data can be updated and then saved again in the database.
Unfortunately jQuery is my weak point and been struggling with this for a while now. Any suggestions or working examples?
Thank you very much in advance.