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

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

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 Denunciar

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