Lets say I have these HTML objects:
<button id="addMore" class="button">+</button>
<div id="fieldList">
<input type="text" name="gsm[]" placeholder="GSM" required>
<input type="text" name="gsm[]" placeholder="GSM" required>
<input type="text" name="gsm[]" placeholder="GSM" required>
</div>
Now I want to loop through each one of them in JavaScript. Each of the input text has different values. This is what I have tried (the current code is a small snippet of a bigger code):
$('input[name^="gsm"]').each(function(i,obj) {
var eachGsm = $(this).val();
"This line has " + eachGsm[i] + ", as the value." + "%0D%0A" +
});
When running this, the script gives me: [object Object]. What is the correct approach?
eachGsmisn't an array , on youreachloopeachGsmcontains your input type text value, if you want an array you have to create it and push the values inside