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

104
Visualizações
Replace text on click radio button and change it back to the original text if clicked on other radio button

String replace is working fine for me, But how to bring the last clicked radio button label text back to the original text?

function myFunction(id) {
    var str = document.getElementById(id).innerHTML; 
    var res = str.replace("{#var1#}", "<input type='text' name='var1' maxlength='30' size='30'>")
        .replace("{#var2#}", "<input type='text' name='var2' maxlength='30' size='30'>")
        .replace("{#var3#}", "<input type='text' name='var3' maxlength='30' size='30'>")
        .replace("{#var4#}", "<input type='text' name='var4' maxlength='30' size='30'>");
         document.getElementById(id).innerHTML = res;
}

Here is my PHP,HTML Code:

  <tr>
      <td><input onchange="myFunction('<?php echo $row['id']; ?>')" type="radio" name="id" value="<?php echo $row['id']; ?>" required></td>
      <td><b><?php echo  htmlspecialchars($row['template_name']);  ?></b></td>
      <td id="<?php echo $row['id']; ?>"><?php echo  str_replace("\n","<br />",htmlspecialchars($row['template_content']));  ?></td>
  </tr>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think you should add an extra attribute in the input instead (it can be data-origin or some thing like that). For example:

<input value="">
<div class="display" data-origin="xxxx"></div>

And then make a function trigger the change on the input:

$(input).onchange(() => {
    $(display).innerHtml = $(display).attr(data-origin)
});
//===continue your stuff====
over 4 years ago · Santiago Trujillo 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