adplus-dvertising

How to seperate to javascript functions? [closed]

Asked 2 months ago
Viewed 18 times

I am doing a webite which includes two sliders. So here ist my problem:

When changing the second slider, it changes the value of the first one. How can I fix this? Here is my code:

var output = document.getElementById("splitOutput");

var slider = document.getElementById("splitInput").oninput = function() {

  var value = (this.value-this.min)/(this.max-this.min)*100

  output.innerHTML = this.value;
}

var output2 = document.getElementById("tipOutput");

var slider2 = document.getElementById("tipInput").oninput = function() {

  var value2 = (this.value2-this.min)/(this.max-this.min)*100

  output.innerHTML = this.value;
}

asked 2 months ago

Correct Answer

Because you're referencing the same output in both scenarios. Change the second function to this:

var slider2 = document.getElementById("tipInput").oninput = function() {
    var value2 = (this.value2-this.min)/(this.max-this.min)*100
    output2.innerHTML = this.value;
}
answered 2 months ago