Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

653
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda