I\'m looking to create a form which contains a dynamic number of input text boxes. I would like each text box to form part of an array (this would in theory make it easier f
First of all, id
attribute cannot contains [
or ]
character.
There is lots of ways to get jQuery/plain JavaScript references to these elements. You can use descendant selector:
$("#list-of-fields input");
document.getElementById("list....").getElementsByTagName("input");
You can also use attribute selector:
$("input[name^=field]");
I'm not sure whether that's the only way but I think in plain JavaScript you'll have to fetch all input
elements (document.getElementsByTagName
) and then loop through array of these elements and check each element (whether it has name
attribute which value starts with field
).