Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda