Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!