I’m trying to use checkboxes to populate a textarea with certain text; however, when the checkbox is unselected, I’d like to have the populated text deleted. I’ve tried this:
$('input:checkbox').click(function(){
var tb = "#"+$(this).attr('rel');
if($(this).is(":checked"))
$(tb).append(this.name + "\n");
else($(this).not(":checked"))
$(tb).remove(this.name + "\n");
});
to no avail. Halp?
EDIT
Major step forward… I’ve figured-out how to redesign the script to almost do exactly what I need. I altered the above to this:
$('input:checkbox').click(function(){
var tb = "#"+$(this).attr('rel');
if($(this).is(":checked"))
$(tb).append(this.name + "\n")
else($(tb).empty(this.name + "\n"))
});
My only problem now is that when I uncheck a checkbox, it clears all text from the textbox, when I only want it to clear the specific text which corresponds to the unchecked checkbox.
Try the below code it will help you….