Good morning
I created a shopping list with a checkbox and would like to print only the selected checklists.
follow the codes below:
html code
<div class="cont-list carnes">
<h3 class="text-center"><span>Carnes / Aves / Peixes</span></h3>
<div class="col-md-3">
<input value="lombo" type="checkbox" /><label>Lombo</label>
</div>
<div class="col-md-3">
<input value="peixes" type="checkbox" /><label>Peixes</label>
</div>
<div class="col-md-3">
<input value="frango" type="checkbox" /><label>Frango</label>
</div>
<div class="col-md-3">
<input value="carne-suina" type="checkbox" /><label>Carne de Suína</label>
</div>
<div class="col-md-3">
<input value="carne-bovina" type="checkbox" /><label>Carne Bovina</label>
</div>
</div>
I used a jQuery to print the list but I would like it to print only the selected items.
<!--input type="text" id="myVal" value=""-->
<input id="printButton" type="button" value="Imprimir Lista" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.14.0/printThis.min.js"></script><scripttype="text/javascript">
jQuery(function ($) {
/*$(":checkbox").change(function() {
var arr = $(":checkbox:checked").map(function() { return $(this).val(); }).get();
$("#myVal").val(arr.join('/'));
});*/
$("input:button").click(function () {
$('input[type="checkbox"]').each(function() {
var $this = $(this);
if($this.is(':checked')) {
$this.attr('checked', true);
} else {
$this.removeAttr('checked');
}
});
$("#printing").printThis({
pageTitle: "Lista de Compras ",
importStyle: true
});
});
});
</script>