Dear friends,

I have created one form to search the data from the database. the form is having four text button to get input for search. if the search criteria matches, it will display the results on next page.
But I want to print while giving the input data in form as well as I have to print the page with out showing the results of the those input.
I am using php and MySQL for back end. and java script using for window.print();

Please help me,

Dani AI

Generated

Short summary and the simplest fix: the browser prints whatever document is currently loaded, so a Print click on the search page will print the form (not the server-rendered results). The most straightforward approach—also suggested by —is to place the Print control on the result page (or open the results into a printable window/iframe and print that window). The print dialog is opened by the window.print API and it acts on the current document. (developer.mozilla.org)

Two practical patterns to implement

  • Put a Print button on the server-generated results page and use print-specific styles to hide UI and format the output for paper (header/footer, buttons, etc.). Use an @media print stylesheet for that. (developer.mozilla.org)
  • If staying on the search page is required, render the results into a new window or hidden iframe and call print on that browsing context (this keeps the search page visible while the printable document is printed). Opening and writing a new window must be user-initiated (popup blockers and same-origin rules apply). (mdn2.netlify.app)

Print-layout tips (fixes for wide tables and orientation)

  • Add a print stylesheet that hides controls and forces printable rules. Example rules to include (adapt to markup):
@media print {
  .nav, .controls { display: none !important; }
  table { width: 100% !important; table-layout: fixed; }
  th, td { white-space: normal; overflow-wrap: anywhere; }
  body { font-size: 11pt; }
}
@page { size: A4 landscape; margin: 10mm; }

Using fixed table layout plus wrapping prevents long cells from forcing horizontal scroll; @page can request landscape orientation but browser/user settings may override it. (mdn.org.cn)

Troubleshooting notes

  • Test in print preview across target browsers; some ignore @page orientation and require the user to select landscape in the print dialog. Use beforeprint/afterprint handlers only if runtime DOM tweaks are needed (prefer CSS where possible). If output still overflows, hide low-value columns for print or reduce font-size for the print stylesheet. (developer.mozilla.org)

Remarks: ’s button shows the basic window.print call; it works when the printable document is already the active page but won’t print server results that haven’t been loaded into that document. These patterns address printing the correct document, handling overflow, and getting landscape output.

Recommended Answers

All 9 Replies

can you explain a little bit more ?

I have created one form, that contains four text fields. (like date,name, age,location). and I have entered the values to database called "details".

Now I want to print the using print button. when I use to click the print button, it takes the result page to printer and give me printed copy.

the form does not shows the result page, it submits the result values to printer.

give me idea to solve this problem.

regards,
maza

You mean like this ?

<html>
<head>
<script type="text/javascript">
function printpage() {
	window.print();
	return false;
}
</script>
</head>
<body>
<form onsubmit="javascript: return printpage();">
This is the result page. 
<INPUT TYPE="submit" name="submit" value="Print">
</form>
</body>
</html>

Presently I am using this method. Now I am getting print of form only. I want to take a print copy of result page.

Presently I am using this code:

function print_page() 
 {
    window.print(); 
 }
<body>
<form>
<td ><INPUT type="button" name="print" value="PRINT" class="button" onClick="printpage()"> </td>
</form>
</body>

give me suggestion.

why don't you have the same thing in your result page ?

Thanks, I have implemented the print option. But I am getting the output result that exceeds the page.

I mean here, to see the entire page we have to use horizontal scroll then only we view all data. the print option will take output only the screen size. how can I print all the data as per original output.

whether we have option to print all in a single page or only we get print as the screen shows.

suggest me please,

I tried with that way. But I get print the same.

or else how we set the print page to Landscape.

<form>
<input type="button" value="Print this page" onClick="window.print()">
</form>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.