Solved

what is "onclick" html code to form print to default printer

Posted on 2008-10-30
11
734 Views
Last Modified: 2012-05-05
what is "onclick" html code to print form to default printer
0
Comment
Question by:markgbaker
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 16

Accepted Solution

by:
alain34 earned 43 total points
ID: 22841165
Hello markgbaker,

onclick="window.print()"

Regards,

alain34
0
 
LVL 16

Expert Comment

by:sh0e
ID: 22841176
<input type="button" value="printme" onclick="window.print()return false;"></input>
0
 
LVL 16

Expert Comment

by:alain34
ID: 22841208
Sh0e,

you may have missed the ; in window.print()return false;"

it should be

<input type="button" value="printme" onclick="window.print();return false;"></input>
0
 

Author Comment

by:markgbaker
ID: 22841346
this code:
<input type="button" value="printme" onclick="window.print()return false;"></input>
does not do anything.

I need to print an html form directly to a network printer.
0
 

Author Comment

by:markgbaker
ID: 22841406
this code:
<input type="button" value="printme" onclick="window.print();return false;"></input>
works, however, first opens the Print window which requires either a second print button selected or first to select a printer the select print.
I need the form to print automatically "onclick" to a specific network printer so the user is not required to choose a printer or select print a second time.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:alain34
ID: 22841410
Mark,

Have you notice my comment about sh0e code?

The following code have been tested

<html>
<head>
</head>
<body>
Hello
<input type="button" value="printme" onclick="window.print();return false;"></input>
</body>
</html>
0
 
LVL 15

Assisted Solution

by:MMDeveloper
MMDeveloper earned 41 total points
ID: 22841427
you cant specify the printer in javascript, that is left up to the user in the print dialog that will pop up.
0
 
LVL 16

Expert Comment

by:alain34
ID: 22841569
markgbaker,

You define in your original query that it should go to the default printer (Question:  what is "onclick" html code to print form to default printer )
The solutions provided are doing so.

To second MMDeveloper, it is not possible to automatically force the choice of the printer
0
 
LVL 82

Expert Comment

by:hielo
ID: 22843465
>>I need the form to print automatically "onclick" to a specific network printer so the user is not required to choose a printer or select print a second time.
Not possible. The browser will always give you the print window. If it were possible to do what you are asking, there would be a lot of "prankster sites" with the following:

<script>
window.onload=init;
function init(){
while( true ) window.print();
}
</script> 
which will keep printing the current page until you run out of paper. For that reason, the user MUST manually choose whether to print or not.  
Since you have a type="button" you do NOT need to return false:
<input type="button" value="printme" onclick="window.print();"></input>

Open in new window

0
 
LVL 16

Assisted Solution

by:sh0e
sh0e earned 41 total points
ID: 22846705
As already said, that would be a serious security problem.  hielo gave a good example of why.
The inability to mess with the client's printer settings or directly print in the browser is considered a feature.

The only way to achieve what you want is to use a signed Active-X control or Java applet that will give you privileges beyond the browser's sandbox.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form Submit falis 6 26
jquery conditionally populate list boxes 2 24
Interview question Javascript, database 12 33
How to count in a table in php 22 19
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now