I have a form that I want to be filled with a modal dialog. It uses input arrays but as these inputs are outside the < form>< /form> tags, they are not posted.
Here is the modal code :
<div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="form-row field" id="auteur1">
<div class="form-group col-md-5" style="margin-bottom:0">
<input autocomplete="off" class="form-control auto_c" name="name_add[]" type="text" />
</div>
<div class="form-group col-md-4" style="margin-bottom:0">
<input type="text" class="form-control" name="firstname_add[]" />
</div>
<input type="hidden" name="id_add[]" value="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="save btn btn-qvq">Submit</button>
</div>
</div>
</div>
</div>
There can be many lines, here is why arrays are used.
I'd like to fill name[], firstname[] and id[] arrays that are located inside the < form>< /form> tags:
<input type="hidden" id="name" name="name[]" value="">
<input type="hidden" id="firstname" name="firstname[]" value="">
<input type="hidden" id="id" name="id[]" value="">
I guess it souhld be something likre that but it doesn't work. (example for names only)
$(function() {
$('.save').on('click', function() {
$.each($("input[name='name_add[]']"), function(idx, value) {
$("input[name='name[]']").eq(idx).val(value);
});
}
}
Any help will be appreciated. Thanks.
Edit
As per Steph74 answer I have tried:
$('.save').on('click', function(){
$.each($('input[name="name_add[]"]'), function(idx, v) {
$('input[name="name[]"]').eq(idx).val(v.value)
})
})
name[] is now filled but only with the first value if there are multiple name_add[] inputs