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

206
Vistas
check if radio button is checked in ejs

As the title says,I'm trying to check if radio button is checked,but since document isn't available,how am I supposed to do it? I want to achieve

<%if(radio1.checked){%>
 <%-include('./someHtml')%>
<%}%>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Assuming you care only about the state at the time the document loads:

There's no document, but there's no radio button either.

What you have is some data and an EJS program.

The EJS program must already have some logic to examine that data and determine if it should output a checked attribute (or not) for each radio button.

Use that same logic to determine if the include should be used.


If, on the other hand, you want to change what is displayed, live, as the user clicks on radio buttons then you can't do that in EJS.

By the time the HTML is delivered to the browser, turned into a DOM, and rendered where the user can click on it: the EJS has finished.

You can either:

  • Use client-side JS to change what content is shown or
  • Replace the radio buttons with links or submit buttons and load a whole new page from the server based on the submitted data

Related reading:

  • What is the difference between client-side and server-side programming?
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can either send an Ajax request when clicking the radio button and handle it's state in the backend or show/hide 'someHtml' using Javascript:

<input
  type="radio"
  name="toggleHtml"
  onclick="document.getElementById('someHtml').style.display = 'block';" checked
/> Show

<input
  type="radio"
  name="toggleHtml"
  onclick="document.getElementById('someHtml').style.display = 'none';"   
/> Hide

<div id="someHtml">Some HTML ...</div>
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