Okay, so I have the following line of Javascript for which I'm trying to use to change the name attribute of an input element, following a click on a div element seperate from the input element.
Because I wish for the name attribute of the input element to change multiple times following separate clicks, I have attempted a for loop as seen below.
Javascript
document.getElementById('btn').addEventListener("click", function() {
var letters = ["a", "b", "c", "d", "e"];
for (var i = 1; i < letters.length; i++) {
document.getElementById('textinput').name = letters[i];
}
});
This code is successful in changing the name attribute of the element with id textinput, however, it automatically changes it to e, and does not cycle through the for loop, despite however many clicks are performed.
I am unsure on the issue and have had difficulty finding a suitible solution here on stackOverflow, so any answers to this issue are deeply appreciated. Thanks in advance!