0

I have a problem with printing a window, parts of window specifically. Site is Joomla. Javascript for printing:

function printDiv(divName) {

        var printContents = document.getElementById(divName).innerHTML;

        var originalContents = document.body.innerHTML;

        document.body.innerHTML = printContents;

        window.print();

        document.body.innerHTML = originalContents;
}

<input type="button" onclick="printDiv('printableArea')" value="Print" />

Part I want to print is in this html block:

<div class="order-info-container" id="printableArea">

Everything gets generated properly except for Comment section in which comments are posted with Javascript again and this is the code block for generating them:

    <?php if(count($this->comments)):

    foreach ($this->comments as $key => $comment) { ?>

    <div class="comment-container" id="comment">

        <div class="comment-user-info-block">
            <div class="comment-name"><h5><?php echo $comment->name; ?></h5></div>
            <div class="comment-created"><?php echo date('Y-m-d', strtotime($comment->created)); ?></div>
        </div>

    <div class="comment-content"><?php echo $comment->comment; ?></div>

    </div>
    <?php } 
    endif;?>

They are in the big printable Area container so I'm really not sure why they aren't appearing on the print page. Everything else works fine.

For anyone interested, this is where I found print solution which works perfectly

SOURCE!

Community
  • 1
  • 1
  • I'm sorry if question wasn't specific enough. I don't want anyone doing it for me but just some guidance on why they might not be appearing. – Denin Korjenic Aug 21 '16 at 17:08
  • wrong "divName" in function?) – KoIIIeY Aug 21 '16 at 17:16
  • 3
    Don't do this. Instead, use `@media` queries to govern the parts you want to print. –  Aug 21 '16 at 17:16
  • its not wrong divName, it's a function that can be reused with any matching input button. Anyways, I fixed it: problem was that foreach loop was generating each comment with a same ID "comment". Works fine now. Thanks guys – Denin Korjenic Aug 21 '16 at 17:18

0 Answers0