Looking to give sequential numbering to elements by iterating through them.
For instance, if there are 6 input elements, the goal is to update their names correspondingly like "name=input1", "name=input2", and so on. This involves using a for loop to reassign names each time an element is added or removed.
Below is the function that's attempted (and struggling) to be executed:
function count(){
console.log(numChildren)
var childCount = document.getElementById("items").childElementCount;
console.log(childCount + " = number of children")
numChildren = [];
for (var i = 0; i < childCount; i++) {
numChildren.push(i+1)
document.querySelector("input[name*='item_name_']").name = "item_name_" + numChildren[i];
}
};