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

160
Vistas
html change/replace string after input

function convertUnits(obj) {
  if($(obj).is(":checked")){
    $(obj).after(' "');
  }else{
    $(obj).after(' mm');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type='checkbox' id='units' onchange="convertUnits(this)"/>
    </td>
  </tr>
  <tr>
</table>

I'm trying to change/replace text after a text input depending on which radio button is chosen.

I can add text but it doesn't replace it...

I'm using this code to add the text... convInputs is an array of all the inputs I want to add text to the end of the input. Depending on the checkbox selected it's either ' /', ' "' or ' mm' like in the example text.

Right now when I switch checkbox the text is just added together and not replaced with the new text... ie: / " mm.

[https://jsfiddle.net/frankn/c6mjvLxd/19/][1]

edit: added jsfiddle with a simplified code example of my actual code and what's happening.

edit #2: as suggested I added code snippet here.

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

0

Well after a messy question and some help and suggections... here's what I came up with...

function convertUnits(obj) {
  if($(obj).is(":checked")){
    $(obj).next().remove()
    $(obj).after("<label> test</label>")
  }else{
    $(obj).next().remove()
    $(obj).after("<label> new</label>")
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type='checkbox' id='units' onchange="convertUnits(this)"/>

    </td>
  </tr>
  <tr>
</table>

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