Reputation: 472
I'm trying to give my users the ability to add multiple values, if needed. I using the following JS form:
<script type="text/javascript">
var counter = 1;
var limit = 3;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]' value=''>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
</script>
The following form:
<form action="add.php" method="post" ENCTYPE="multipart/form-data">
<div id="dynamicInput">Entry 1<br><input type="text" name="myInputs[]"></div>
Enter the POC's number<br>
<input type="button" value="Add another POC" onClick="addInput('dynamicInput');">
<input type="submit" name="Submit" id="Submit" value="Submit">
</form>
If I fill in the first value as 123 and the second value as 124, once it posts to add.php, I only get the first value. I've confirmed the values are not posting (through print_r($_POST);) and through firebug.
Array ( [myInputs] => Array ( [0] => 123 )
Can anyone find why I'm losing the rest of the array?
Upvotes: 1
Views: 232
Reputation: 4981
There is the form handler in your site, because array element [Submit] => Submit is losted too. Check it on the single php-page. I think problem is not in this script or this form.
Upvotes: 1