PDA

View Full Version : print content of textbox


_Gizmo_
03-29-2004, 07:39 PM
Hi all,

on my page I have a textbox (HTML input element) where I display large texts. How can I print the content/text of the textbox?


Thanks

markus

sad69
03-29-2004, 10:03 PM
I guess my post didn't go through... codingforums maintenance..

I didn't answer your question as I need some more information.

When you say print the textbox data, do you want to print to a printer, or print to the screen (ie. an alert dialog box).

Also when you say large texts, I keep thinking you're using a textarea as opposed to an input text.

Please elaborate a little more, and I'll offer some answers.

Sadiq.

_Gizmo_
03-30-2004, 06:22 AM
I would like to print to a printer. I am using IE, other browsers do not need to be supported.

You're right, I'm using a textarea, not just a text input.


Thanks

Markus

sad69
03-30-2004, 07:18 AM
Try this link out and see how it works out for you:
http://www.ahfb2000.com/webmaster_help_desk/showthread.php?t=2613

Hope that helps,
Sadiq.

Kor
03-30-2004, 07:44 AM
Or see the attachment, it might help you, I hope

_Gizmo_
03-30-2004, 04:16 PM
Thanks, your postings were helpful. I thought there might be a way to print it without opening a new window, but this seems to be the easiest way to do it.

Markus

glenngv
03-31-2004, 06:53 AM
There is a way to print the input without opening a window.
See the attachment below. Tested in IE6.0, NS7.02 and Moz1.0

Candyass
05-24-2004, 03:45 AM
glenngv - thanks for your solutions above - works like a charm.

My question is regarding the iframe. Is this only used if you don't want to open another window before printing?

I'd like the printing option to be as cross browser as possible - would I be better off just using the 'else' option as in your original example / now modified code below?


var html='<html><head><style type="text/css">div{font:normal 12px Arial}</style></head>'+
'<body onload="window.print();window.close()">'+
'<div>'+
'<b>'+'ADSTAMP ONLINE ORDER PREVIEW'+'</b>'+' - '+(d.getMonth() + 1)+' / '+(d.getDate())+' / '+(d.getFullYear())
+'<br><br>'+
'<b>'+'Account Name: '+'</b>'+f.reqAcctName.value
+'<br>'+
'<b>'+'Name: '+'</b>'+f.Name.value
+'<br>'+
'<b>'+'Company: '+'</b>'+f.Company.value
+'<br>'+
'<b>'+'Email: '+'</b>'+f.reqEmail.value
+'<br>'+
'<b>'+'Ship To: '+'</b>'+f.reqShipType.value
+'<br><br>'+
'<b>'+'Client Names: '+'</b>'
+'<br>'+
f.reqClientNames.value.replace(/\n/g,'<br />')
+'<br><br>'+
'<b>'+'Special Instructions: '+'</b>'
+'<br>'+
f.specialInstructions.value.replace(/\n/g,'<br />');
'</div>'+
'</body></html>'

var win = window.open('','_blank','menubar,scrollbars,resizable');
win.document.open();
win.document.write(html);
win.document.close();


Thanks,
Matz

glenngv
05-24-2004, 04:14 AM
glenngv - thanks for your solutions above - works like a charm.

My question is regarding the iframe. Is this only used if you don't want to open another window before printing?

I'd like the printing option to be as cross browser as possible - would I be better off just using the 'else' option as in your original example / now modified code below?


Yes, the iframe is used for printing a page without opening a new window.
As far as I can remember, I tested my code in NS7, Moz1, IE6 and it all worked. Just test the original code in all your target browsers before implementing the "else" option.

Candyass
05-24-2004, 04:24 AM
Sweet!
Thanks again!

Candyass
05-24-2004, 05:14 AM
hmmm...I jumped too soon. It seems like it's not functioning properly in Netscape 7.1 - probably because I use images and have to "submits" in a sense. When I hit the print button in NS 7.1 it thinks I'm trying to submit the form. The buttons I have are like this:

<input type="image" src="images/btn_print.gif" name="print" id="print" border="0" onMouseOver="window.status='Get a Printed Record of My Order';return true;" onMouseOut="window.status='';return true;" onclick="printInput(this.form);return false">

...then the other button submits the form:
<input type="image" src="images/btn_submit.gif" name="submit" id="submit" border="0">

Any idea how to get around this?

Thanks,
Matz

glenngv
05-24-2004, 05:40 AM
That should work because you cancel the submission by returning false to the onclick handler. But if there is a runtime error, true is returned to the handler, thus the submission will continue. Please check the Javascript console if it throws any error.

In any case, you can always use image hyperlinks instead of submit buttons.

<a href="#" onclick="printInput(document.theForm);return false"><img src="images/btn_print.gif" border="0" /></a>