What you are doing should work, but another way of doing it is (slightly more efficient):
function addInput() {
var input = createTextInput({
"type": "text",
"name": "box[0]",
"id":"box[]",
"value": "This is a value"
});
document.getElementById("inputs").appendChild(input);
}
// warning: just to be safe, don't pass any option object that extends any
// browser's native object or built in objects.
function createTextInput(options) {
var i = document.createElement("input");
for(key in options) {
i[key] = options[key];
}
return i
}
function getValues() {
var div = document.getElementById("inputs");
var values = [];
var textBoxes = div.getElementsByTagName("input");
for(var i = 0, len = textBoxes.length; i < len; i++) {
var box = textBoxes[i];
if(box && box.name === "box[]") {values.push(box.value);}
}
return values;
}
There are other ways of doing it, e.g. using jQuery, its much simpler and less verbose, but this is just the plain 'ol js way