Solved

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

Posted on 2008-10-30
11
730 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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 …

747 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

10 Experts available now in Live!

Get 1:1 Help Now