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

651
Views
Function is declared but its value is never read

The function is working on the HTML page but not working from the external JS file and showing this error ('checkSelection' is declared but its value is never read). Is there any solution for this?

   function checkSelection(that) {
    if (that.value == "web-dev") {
      document.getElementById("web-section").style.display = "block";
    } else {
      document.getElementById("web-section").style.display = "none";
    }
    if (that.value == "grp-dsg") {
      document.getElementById("graphic-section").style.display = "block";
    } else {
      document.getElementById("graphic-section").style.display = "none";
    }
    if (that.value == "dgt-mkt") {
      document.getElementById("marketing-section").style.display = "block";
    } else {
      document.getElementById("marketing-section").style.display = "none";
    }
  }
<input onchange="checkSelection(this);">

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

That is an error reported by the TypeScript checker in your IDE. To make it go away, this would be a workaround:

window.checkSelection = function(that) {
    if (that.value == "web-dev") {
      document.getElementById("web-section").style.display = "block";
    } else {
      document.getElementById("web-section").style.display = "none";
    }
    if (that.value == "grp-dsg") {
      document.getElementById("graphic-section").style.display = "block";
    } else {
      document.getElementById("graphic-section").style.display = "none";
    }
    if (that.value == "dgt-mkt") {
      document.getElementById("marketing-section").style.display = "block";
    } else {
      document.getElementById("marketing-section").style.display = "none";
    }
  }

The basic problem though is your use of inline event listeners, which is widely considered bad practice. Instead, I'd recommend you give that input an id and use addEventListener:

document.getElementById('section-picker').addEventListener('change', function() {
    if (this.value == "web-dev") {
      document.getElementById("web-section").style.display = "block";
    } else {
      document.getElementById("web-section").style.display = "none";
    }
    if (this.value == "grp-dsg") {
      document.getElementById("graphic-section").style.display = "block";
    } else {
      document.getElementById("graphic-section").style.display = "none";
    }
    if (this.value == "dgt-mkt") {
      document.getElementById("marketing-section").style.display = "block";
    } else {
      document.getElementById("marketing-section").style.display = "none";
    }
  });

If you take this advice, you need to make sure the Javascript executes after that input in the page is parsed. The easiest way to achieve that is by applying the defer attribute in the script tag.

about 4 years ago · Juan Pablo Isaza Report

0

you need listen for the input first before using that in your function

let number = document.querySelector('input');

function check(that){
  if(that.value == 1){
    console.log('hello');
   }
   else{
    console.log('bye');
   }
 }
 
 number.addEventListener('input', ()=>{
  check(number);
 });
<input type="number">

take this for an example, you assign the input to a variable and then whenever that number is changed you run the function to check the value and display the result. same thing goes for checkbox too.

about 4 years ago · Juan Pablo Isaza Report
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!