Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Probably a really simple thing but I can't seem to pass an argument into my Javascript function

I am very new to JS I just created my very first web app but I am having trouble tidying up my code.

My HTML has 3 range sliders I take the value from each and change the color of the thumb depending on that value (RAG). It works fine the way I have implemented it but I have repeated myself quite a bit.

document.getElementById(complex).addEventListener("change", complexityFunction);
document.getElementById(uncert).addEventListener("change", uncertaintyFunction);
document.getElementById(repeat).addEventListener("change", repetitionFunction);

function complexityFunction() {
  var x = document.getElementById(complex).value;
  if (x == 1) {
      this.className = "green";
  } else if (x == 2) {
      this.className = "amber";
      } else {
          this.className = "red"
      }
  }

function uncertaintyFunction() {
  var x = document.getElementById(uncert).value;
  if (x == 1) {
      this.className = "green";
  } else if (x == 2) {
      this.className = "amber";
      } else {
          this.className = "red"
      }
  }

function repetitionFunction() {
var x = document.getElementById(repeat).value;
if (x == 1) {
    this.className = "green";
} else if (x == 2) {
    this.className = "amber";
    } else {
        this.className = "red"
    }
}

Here's what I have tried (amongst other things) which hasn't worked!:

document.getElementById(complex).addEventListener("change", assessmentFunction(complex));
document.getElementById(uncert).addEventListener("change", assessmentFunction(uncert));
document.getElementById(repeat).addEventListener("change", assessmentFunction(repeat));

function assessmentFunction(argument) {
  var x = document.getElementById(argument).value;
  if (x == 1) {
      this.className = "green";
  } else if (x == 2) {
      this.className = "amber";
      } else {
          this.className = "red"
      }
  }

Can somebody please help me out?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!