Solved

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

Posted on 2008-10-30
11
737 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

772 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