Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-30
11
Medium Priority
?
753 Views
Last Modified: 2012-05-05
what is "onclick" html code to print form to default printer
0
Comment
Question by:markgbaker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 16

Accepted Solution

by:
alain34 earned 172 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

Technology Partners: 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

Find out what you should include to make the best professional email signature for your organization.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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 …

704 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