I would greatly appreciate an answer to my question. It's been bugging me for days. I have a list of inputs in my form.
<!DOCTYPE html>
<html>
<div class="form">
<form id="myForm" onsubmit="myFunction()">
<input type="text" id="item1">
<input type="text" id="item2">
<input type="text" id="item3">
</form>
</div>
<br><br><br><be>
But I want to do this programmatically for a varying number of items, so I tried something like this:
<script>
for (i=1; i<=3; i++) {
item[i] = document.createElement("input");
item[i].setAttribute("type", "text");
myForm.appendChild(item[i]);
}
But it doesn't seem to work. It would work if I didn't use indexed names, but fixed item names, like:
item1 = document.createElement("input");
item1.setAttribute("type", "text");
myForm.appendChild(item1);
But that's not what I need. Can you help me?
</script>
</html>