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

245
Visualizações
when a box is unchecked it clears the previously populated text from checkbox

how do I clear the previously populated text from the checkbox when I uncheck the box?

the list below codes is when you check a box and populated text in the text area.

$('input:checkbox').click(function(){
    var tb = "#"+$(this).attr('rel');
    if($(this).is(":checked"))
        $(tb).append(this.name + "\n");

        else($(tb)).removeAttr(":checked");
})
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the replace() function to remove the name from the text field.

$('input:checkbox').click(function() {
  var tb = "#" + $(this).attr('rel');
  let text_to_add = this.name + "\n";
  if ($(this).is(":checked")) {
    $(tb).append(text_to_add);
  } else {
    let remove = this.name + "\n";
    $(tb).text(function(i, text) {
      return text.replace(text_to_add, '');
    });
  }
})

about 4 years ago · Juan Pablo Isaza Relatório

0

The following script assembles the checked checkboxes' name attribute values and places them into the textbox that is addressed by the checkbox's rel attribute:

$('input:checkbox').click(function(){
    var tb = $(this).attr('rel');
     $("#"+tb).val($("[rel="+tb+"]:checked").map((i,e)=>e.name).get().join("\n"))

})
textarea {height:50px}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label><input name="one" type="checkbox" rel="mytext">one</label>
<label><input name="two" type="checkbox" rel="mytext">two</label>
<label><input name="three" type="checkbox" rel="mytext">three</label><br>
<textarea id="mytext"></textarea>
<br>
<label><input name="four" type="checkbox" rel="text2">4</label>
<label><input name="five" type="checkbox" rel="text2">5</label>
<label><input name="six" type="checkbox" rel="text2">6</label><br>
<textarea id="text2"></textarea>

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