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

173
Vistas
Can't change radiobuttons display to none again

i got a container with 3 radionbuttons and 2 of the radiobuttons have another radiobuttons next to them but their displays are none . When i click the radiobutton i wanna display the hidden radiobuttons and when i click another radionbutton i want it's display to be none again .

`function showHiddenText() 
{
  if (document.getElementById("diger").checked) {
    const hiddenInput = document.getElementById("hidden-input");
    hiddenInput.style.display = "block";
  } else if (document.getElementById("diger").checked == false) {
    hiddenInput.style.display = "none";
  }
}`

It's a simple function i write to do that but else if part is not working . When i display hidden radio buttons they dont disappear ever again. radionbuttons hiddenpart

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

const variables are block scoped. So, in the else if statement hiddenInput is undefined.

Move it above the statements

function showHiddenText() 
{
  const hiddenInput = document.getElementById("hidden-input");
  if (document.getElementById("diger").checked) {
    hiddenInput.style.display = "block";
  } else if (document.getElementById("diger").checked == false) {
    hiddenInput.style.display = "none";
  }
}

By the way, you can make it simpler by replacing the else if statement with else:

function showHiddenText() 
{
  const hiddenInput = document.getElementById("hidden-input");
  if (document.getElementById("diger").checked) {
    hiddenInput.style.display = "block";
  } else {
    hiddenInput.style.display = "none";
  }
}

Or even more:

function showHiddenText() 
{
  const hiddenInput = document.getElementById("hidden-input");
  if (document.getElementById("diger").checked) {
    hiddenInput.style.display = "block";
    return true; // you can return anything here
  }
  hiddenInput.style.display = "none";
  return false; // and here (it is not necessary to return here)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Make sure your radio buttons have the same name. Radio buttons with same name are compared to each other. Add onclick="showHiddenText()" to inputs, then:

html:

<input type="radio" name="btn" id="diger" onclick="showHiddenText()">
<input type="radio" name="btn" onclick="showHiddenText()">
<input type="radio" id="hidden-input">

js:

function showHiddenText() {
  if (document.getElementById("diger").checked) {
    document.getElementById("hidden-input").style.display = 'block'
  }
  else{
    document.getElementById("hidden-input").style.display = 'none'
  }
}
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