I have an input that is appended by jQuery when the "Add another account" button is clicked. Because they all have the same name, only one result is retrieved in JSON, which is the last result "3123213".
I'm trying to get all the results from the input field in JSON like : accountsToLink":[ "3453453453", "3543453453", "5345345345" ] , but couldn't find a way to do it with jQuery append.
Please help!
<div class="input-group mb-3 input_fields_wrap">
<input type="text" class="form-control mx-auto" id="inputAccountNumber" name="accountsToLink" placeholder="9102031012" maxlength="10" required>
<div class="input-group-append">
<button class="btn btn-outline-danger" type="button"><strong>x</strong></button>
</div>
</div>
<div class="text-center mt-4">
<button class="btn-outlined add_field_button">Add another account</button>
</div>
<script>
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div class="input-group mt-3 additional-acc-number"><input type="text" class="form-control mx-auto" name="accountsToLink" placeholder="9102031012" maxlength="10"><div class="input-group-append"><button class="btn btn-outline-danger remove_field" type="button"><strong>x</strong></button></div></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault();
$(this).parent('div').parent('div').remove(); x--;
});
</script>
