Solved

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

Posted on 2008-10-30
11
741 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

713 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