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

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

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 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