So I have a class two class named "Form" and "Question". "Form" contained an array of Question. When I add a question in the array, I call a method called render() in each question
render() {
let htmlElement = document.getElementById("formBody");
let id = Question.GenerateID();
htmlElement.innerHTML += `
<div class="p-2">
<input type="text" class="input-transparent w-100" id="${id}.t" value="${this.Title}" placeholder="Unnamed question">
</div>`;
/**
* @param {int} id
*/
let questionNameChange = function(id) {
this.Title = document.getElementById(id + ".t").value;
};
document.getElementById(id + ".t").onchange = questionNameChange.bind(this, id);
}
Image of the form
The problem is that the element.onchange, which allows me to change the title of a question.
When I change the title of any questions, via the input text, it only works on the last question that has been rendered.
Am I doing anything wrong?