javascriptjqueryprintthis

PrintThis Not Capturing Checked Checkboxes


So I am using the PrintThis JQuery plugin in order to print a form field, but for some reason I am unable to have the plugin print out any changes made to the checkboxes. When I click "Print", the only checkbox that appears to change is one that has a "checked" property by default. Any ideas on how to fix this?

HTML:

<body>

<div id="print">
  <form>
    <input id="option" type="checkbox" checked>
    <label class="checkbox" for="option">&nbsp;&nbsp;You are 18 years or older</label>
    <br><br>
    <input id="option2" type="checkbox">
    <label class="checkbox" for="option2">&nbsp;&nbsp;You have tested positive for something in your blood</label>
    <br><br>
    <input id="option3" type="checkbox">
    <label class="checkbox" for="option3">&nbsp;&nbsp;You have health-related kidney problems</label>
    <br><br>
    <input id="option4" type="checkbox">
    <label class="checkbox" for="option4">&nbsp;&nbsp;You have health-related skin problems</label>
    <br><br>
    <input id="option5" type="checkbox">
    <label class="checkbox" for="option5">&nbsp;&nbsp;You have a low platelet count</label>
 </form>        
</div>

<br>
<br>

<input id="printButton" type="button" value="Click here to download and print this checklist to review with your doctor." />


</body>

JSFiddle: http://jsfiddle.net/Hybridx24/bxtpv26x/


Solution

  • Not sure what the problem might be here, but you can get around it by explicitly setting the checked attribute for the checkboxes that are checked.

    $("input:button").click(function () {
        $('input[type="checkbox"]').each(function() {
            var $this = $(this);
            if($this.is(':checked')) {
               $this.attr('checked', true);
            } else {
                $this.removeAttr('checked');
            }
        });
        $("#print").printThis({'importStyle': true});
    });
    

    Check Fiddle