HTML! I need a button (like a submit button) that will act as a <CTRL><P> in a webpage!

jonnyGURU

Moderator <BR> Power Supplies
Moderator
Oct 30, 1999
11,815
104
106
So, I have this webpage I'm making for my wife and one of the pages is a form you're supposed to print out and mail in. I want to make it easier on people than to tell them to go to FILE/PRINT/, etc. so instead, I'd just like a button that would emulate the CTRL P keystroke and open up the PRINT dialog box.

Any ideas on how to do this????

Thanks in advance!

<edit> Another thing I miss about UBB... SMILIES OFF! :p </edit>
 

perry

Diamond Member
Apr 7, 2000
4,018
1
0
Try making a normal button. Add a JavaScript event that calls window.print(); when clicked.

Kinda like this:

<form>
<input TYPE=&quot;Button&quot; VALUE=&quot;Print&quot; ONCLICK=&quot;window.print()&quot;>
</form>


Quick demo of it here.

Now, if you really wanted to be slick. Have a 'pretty' version of the form pop up in the background in another window after pressing submit. Then you can print that background page and close it.
 

jonnyGURU

Moderator <BR> Power Supplies
Moderator
Oct 30, 1999
11,815
104
106
perry, I LOVED your example. I had no idea that there was an imbedded window.print() javascript tag. That helps so much!

Unfortunately, my wife wants something more idiot proof. So I just took your suggestion and made a script (that's why I've been away from this thread for almost a half an hour):

<script language=javascript>
function printPage() {
if (window.print) {
agree = confirm('You must now print out this page \nso 8 copies can be mailed to the commitee. \n\nPress OK to print now! \n\nIf you cancel, you can print the page by pressing CTRL P.');
if (agree) window.print();
}
}
</script>

and then I just put an OnLoad=printPage() in the BODY tag.

Of course I could have just made it COMPLETELY idiot proof and just put BODY OnLoad=window.print()

Hmm.... Wonder if that would work. :p

Man, I'm writing up all sorts of javascript on this project. I've just about learned all the hexadecimal values for characters like $ and @ and <br> because if you type them into the form that gets printed, they come up with %20 and %2F and such. I had to make a filter that converted those characters back to their original appearance! :Q

What's next?!?!?
 

Zoltar

Senior member
May 1, 2000
796
0
0
All I know is if I start browsing the web and all of a sudden my printer goes nuts, I will be seriously pissed off!

Even if the print dialog comes up I would be seriously miffed. :|
 

Cruisin1

Golden Member
Oct 10, 1999
1,119
0
71
Is it really that difficult to find the pictur of the printer on your netscape/IE browser bar? hehe.. I mean seriously, but I guess you can use that javascript command.
 

jonnyGURU

Moderator <BR> Power Supplies
Moderator
Oct 30, 1999
11,815
104
106
Trust me.

I deal with people all day that don't even know what I mean by &quot;RIGHT CLICK&quot;. They NEED help with printing a screen. They really do. :p
 

jonnyGURU

Moderator <BR> Power Supplies
Moderator
Oct 30, 1999
11,815
104
106
Jackass. It's javascript, not java and I've got it now, thank you very much. :p