Forums

Two print buttons conflict

marcinwolejko 13 Aug, 2014
Hi guys.

Maybe you will be able to help me.

I have a tabbed form with two additional tabs showing results from a data entered into CCv4.
One tab showing i.e. receipt and the other for an invoice.

I have two print buttons set up for each tab. The content is wrapped in divs. One div (print1) the other (print2).
However, only one print button is visible on the first tab, the other one I cannot get to work. On changing the visibility to visible (on the second button on tab2) I've managed to show the button but it prints out the data from the first tab.

Please help. How can I make it work so that the print buttons actually print data from separate tabs.

Thanks in advance for your help!

Marcin.
GreyHead 13 Aug, 2014
Hi Marcin,

What JavaScript are you using to get the print buttons to work?

Bob
marcinwolejko 13 Aug, 2014
Hi Bob,
it's the one from FAQ

<?php
$doc =& JFactory::getDocument();
$script = "
function printPage()
{
    var html, css, csss_file, printWin;
    css = \"\";
    css = \"<style type='text/css'>\"+css+\"</style>\";
    css_url = '';
    if ( css_url !== '' ) {
        css_url = \"<link rel='stylesheet' type='text/css' href='\"+css_url+\"' media='print' />\";
    }
    html = '<html><head>'+css+css_url+'</head>'+$(id).innerHTML+'</html>';

    printWin = window.open('', '', 'left=100, top=100, width=600, height=400, toolbar=0, scrollbars=0, status=0' );
    printWin.document.write(html);
    printWin.document.close();
    printWin.focus();
    printWin.print();
    printWin.close();
}
var id;
window.addEvent('domready', function() {
    id = 'print_div';
    $('print_button').setStyle('visibility', 'visible');
    $('print_button').addEvent('click', printPage);
});
";
$doc->addScriptDeclaration($script);
?>


It is embedded in the form in the Formatted text together with all other printable data wrapped in a div.
marcinwolejko 14 Aug, 2014
Hi again.
Any ideas Bob?🙂

I've tried all possible codes from the Internet and still cannot get it to work. Well, some of them actually work but I cannot get to print just the contents of the tab - the printPage or window.print function prints out the whole layout of the website. The code from FAQ is just perfect 'cause it only prints out the div.🙂
This topic is locked and no more replies can be posted.