Today I have a problem. I have a HTML Form, which can have a dynamic number of HTML Input Fields for an EMail Address. Via Javascript I want to evaluate those Data ans Post via XMLHttpRequest.
I fetch the Input fields like this:
var elements = document.getElementById("emailmodal").elements["multiple[]"];
Then I want to check, if it is an array, because if I have only one input field elements will not contain an array of elements, but only one element:
if(jQuery.isArray(elements))
{
for(var i = 0; i < elements.length; i++)
{
formData.append("emailreceiver[]", elements[i].value);
}
}else
{
formData.append("emailreceiver[]", elements.value);
}
In case it is an Array, it is going through the Elements via For Loop, and if not, its directly taking the value.
However this doesnt work correctly. Even if I have multiple INputs, the Script tells me, its no array.
The Corresponding HTML is
<div class="form-group input-group">
<input type="text" name="multiple[]" class="form-control" value="<?php echo $kundendaten['Email']; ?>">
<span class="input-group-btn"><button type="button" class="btn btn-default btn-add">+</button></span>
</div>
This is from Bootstrap.
If i make var log to console and I have more then one element than it looks like this:

If I make var log and only have one element it looks like this
What can I do?
Cheers, Niklas

elementsmethod. Can you share the output of elements ?$("form input.email").lengthand check if you have more than one input. Also you can keep a counter with a global variable and update it in the same function that adds additional input elements to your form