for reason button isn't calling script , chrome's console replies error "unexpected token }"
here script:
<script type="text/javascript" src="js/jquery-1.10.2.min.js"> function printcontent(el){ var restorepage = document.body.innerhtml; var printcontent = document.getelementbyid(el).innerhtml; document.body.innderhtml = printcontent; window.print(); document.body.innderhtml = restorepage; } </script>
here button:
echo '<center> <button onclick="printcontent("printable");" class="btn btn-default"> <span class="glyphicon glyphicon-print"></span> print </button> </center> ';
the reason echo cause using php call button depending on situation.
the div it's suppose printing looks this:
<div class="container" id="printable">
you need close <script>
tag imports jquery , create new <script>
tag in can put own javascript, this:
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script> function printcontent(el) { var restorepage = document.body.innerhtml; var printcontent = document.getelementbyid(el).innerhtml; document.body.innerhtml = printcontent; window.print(); document.body.innerhtml = restorepage; } </script>
as mentioned before, made typo while typing innerhtml
, fixed in above code, , error because you're using double quotes twice in onclick
, can fix changing echo
this:
echo '<center> <button onclick="printcontent(\'printable\');" class="btn btn-default"> <span class="glyphicon glyphicon-print"></span> print </button> </center> ';