tags:

views:

24

answers:

1

I have a datatable in a JSP page and a print button. On click of the print button it will open the print option dialog and print the datatable values.

Now, I have button onclick="callsubmit()".

javascript:

function callsubmit(){
    window.print();
    window.opener.document.location = window.opener.document.location.href;
    window.close();
}

This function prints the whole page, but I need datatable values only.

How to write javascript for print particular values?

+1  A: 

Supply a separate CSS stylesheet on media="print" wherein you hide everything expect the table. E.g.

<link rel="stylesheet" href="print.css" media="print">

wherein the print.css look like this:

#header, #menu, #footer, p {
    display: none;
}

This is of course only easy when your HTML is written semantic, else you'll have to bring some modifications in your HTML structure so that it's all nicely separated.

See also:

BalusC
How to open new jsp from button click ? It should be popup window, then this idea also looks good. How to call new jsp page from javascript ?
vinoth
Just point to URL of the JSP. `location = 'page.jsp';` and so on. By the way, in the JS code in your question you're only printing the parent page, not the popup page...
BalusC
In the popup window i can display the values from arraylist and there call window.open();Those values will be print.
vinoth