Hi,
I have a checkbox where if a user clicks it, the address fields gets removed and if he clicks it again, it should add those address fields back.
I can get it to remove it successfully but when I try to add those fields back, I get [object Object] displayed instead.
var detached_fields = '';
//$("input[name='online_only_bus']") is the checkbox
$("input[name='online_only_bus']").click(function(){
if($(this).is(':checked')){
$('.detach_field').each(function(){
//removes 10 elements correctly
detached_fields += $(this).remove();
});
}
else if($(this+':not:checked')){
console.log(detached_fields); //outputs [object Object] 10 times
$("input[name='online_only_bus']").after(detached_fields);
//displays on the form [object Object] 10 times instead of displaying the elements
}
});
for each of the address fields and its <tr> I have added a class called detach_field
If anyone can help me out or point me in the right direction as to how to remove and add elements correctly, I'd appreciate it.
Thankyou.