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

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

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