I have a couple of input fields with the following ID:
<input type="text" name="numberC[]" id="numberC[]">
<input type="text" name="numberC[]" id="numberC[]">
<input type="text" name="numberC[]" id="numberC[]">
I fetch data in JSON format via my ajax call and push()
certain values in my array.
How could I create a loop that will loop through the array and then inserts each value in one of the above input fields?
so let's say I have the following array:
var testArray = ['hi', 'bye', 'stackoverflow'];
and I have the following 3 input fields:
<input type="text" name="numberC[]" id="numberC[]">
<input type="text" name="numberC[]" id="numberC[]">
<input type="text" name="numberC[]" id="numberC[]">
Whenever I loop through it I unfortunately get the highest value in all of my input fields.
I try to loop through my array in JavaScript and insert each value in each input field. so testArray[0]
should go in the first input field, testArray[1]
in the second input field and testArray[2]
in the third.
Sources I used: Find DOM element by ID when ID contains square brackets?