hello everyone I'm relatively new to javascript and I'm trying to use an input range with an onchange event but I make them in a loop from information that I get from the database sort of like this
var splitstring = response.split(String.fromCharCode(30));
for (var i = 0; i < splitstring.length; i++) {
type = details[0];
actualId = details[1];
userId = details[2];
time = details[3];
//that's user details or whatever so i make the H2 and the range
var range = document.createElement("INPUT");
var spanchange = document.createElement("H2");
spanchange.appendChild(document.createTextNode("0 - neutral"));
spanchange.style.cssFloat = "right";
range.setAttribute("type", "range");
range.setAttribute("class", "horizontal-lowest-first");
range.setAttribute("min", "-100");
range.setAttribute("value", "0");
range.setAttribute("name", "range");
var change = function() { ///range onchange to php :)
var ranges = spanchange;
var x = this.value;
var then = x;
if (x < -90) {
then = x + " : " + "Extremely Poor";
} else if (x < -80) {
then = x + " : " + "Very Poor";
} else if (x < -70) {
then = x + " : " + "Pretty Bad";
} else if (x < -60) {
then = x + " : " + "Bad";
} else if (x < -50) {
then = x + " : " + "Not Good";
} else if (x < -40) {
then = x + " : " + "Phhhhst";
} else if (x < -30) {
then = x + " : " + "Oh No!";
} else if (x < -20) {
then = x + " : " + "Needs Work";
} else if (x < -20) {
then = x + " : " + "Crap";
} else if (x < -10) {
then = x + " : " + "Welp";
} else if (x < 0) {
then = x + " : " + "Downvote";
} else if (x == 0) {
then = x + " : " + "Neutral";
} else if (x < 10) {
then = x + " : " + "OH";
} else if (x < 20) {
then = x + " : " + "Better";
} else if (x < 30) {
then = x + " : " + "Yay";
} else if (x < 40) {
then = x + " : " + "Pretty Good";
} else if (x < 50) {
then = x + " : " + "Mediocre";
} else if (x < 60) {
then = x + " : " + "Great";
} else if (x < 70) {
then = x + " : " + "Yes!";
} else if (x < 80) {
then = x + " : " + "Awesome";
} else if (x < 90) {
then = x + " : " + "Very Good";
} else if (x < 100) {
then = x + " : " + "Top Grade";
} else if (x == 100) {
then = x + " : " + "Perfect!!";
}
console.log("inside onchange" + " " + then);
// var x = spanchange.childNodes[0];
// x.replaceData(0, 20,then);
ranges.innerHTML = then;
};
range.onchange = change;
}
then it adds the elements to a div and appends the div to the body then goes through the loop again so in the function for onchange where i put
ranges.innerHTML = then;
it always changes the spanchange in the last for loops iteration so i mean if i change the first appended range, it sets the value of the last appended spanchange but i want it to change the spanchange that was in the same iteration of the for loop as that range, it sounds nuts i know I'm trying to explain, i hope someone can understand
if you can give me any advice id greatly appreciate it thank you