1
see below the following code:
<input type="text" id="task" name="task[]" value="100" />
<input type="text" id="task" name="task[]" value="110" />
<input type="text" id="task" name="task[]" value="120" />
And in jquery, I normally read the array:
$(function(){
var values = $("input[name='task\\[\\]']")
.map(function(){return $(this).val();}).get();
alert(values);
});
Now, when including the manual Intel in the array, it looks like this:
<input type="text" id="task" name="task[1]" value="100" />
<input type="text" id="task" name="task[2]" value="110" />
<input type="text" id="task" name="task[3]" value="120" />
In this case, jquery no longer reads the array. What should be done to make it possible to read?
What’s wrong with php?
– rray
The problem seems to be with the regular expression you are using to recover the Inputs: name='task[]' (omitting the escapes: ). When you entered the number, it was no longer valid. Try replacing it with: $("input[name='task [. ]]"). If it works, watch out because the regular expression is still very specific, and it wouldn’t work with a larger two-digit array, like task[10] for example.
– NewtonWagner
Hello Newton, in this case, could you suggest me another more appropriate regular expression?
– Eduardo
This will take all inputs that start with task and have something next: $("input[name='task.*']")
– NewtonWagner