1
I have the following Input in my file .html
<input type="text" class="form-control" name="option[]" id="option[]">
Whenever the user clicks on the +
on the button next to it, it creates another input
like this one.
I’m trying to get this value with Javascript as follows:
var inputs = document.getElementsByTagName('input');
for(var i=0;i<inputs.length;i++){
if( (inputs[i].name).indexOf('option')>-1 && inputs[i].value!="") {
inputs ++;
}
}
And then I need to pass this amount by POST and go to my page .php
,
that there I receive in the following way:
if(isset($_POST['option[]'])){
$cc = array($_POST['option[]']);
}
You can’t have more than one field with the same id. And this here:
(inputs[i].name).indexOf('option')>-1 && inputs[i].value!="";
? What is the intention? You are doing nothing there, you do not assign the value to any variable. The intention is to have a conditional/if
?– bfavaretto
I’m sorry, I cut out the
if
.. in case it gets like thisif( (inputs[i].name).indexOf('option')>-1 && inputs[i].value!="") {inputs ++;}
– Ana Olivier
Okay, I included that information in the question. And I think I found the problem...
– bfavaretto