Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing / Saving from a TextArea ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
Admittedly I'm working with ASP.NET web forms but someone suggested that javascript would be the way to go with this one ...
I need the ability of printing (to client default printer) and saving (to client machine) the text as input in a textarea component on the form.
I've been pointed toward the syntax "execCommand('SaveAs', false, '.txt')" / "execCommand('Print', false, '.txt')"
However I can't seem to control it such that it only prints / saves the text from one specified textarea control.
Is this acheivable ?
If so, how ?
Thanks in advance
Steve
 

You could try loading the text from the textarea into a popup and using JS to initiate a print of that page.
Code:
window.onload = self.print();
Remember that your users will still be presented with the Windows print dialogue box.

You could try something similar for SaveAs I suppose, though I have no idea if it will work. execCommand() is Internet Explorer only so I've never bothered with it.

HTH.
 
what kind of control do u want???

Known is handfull, Unknown is worldfull
 
I'm none too familiar with javascript - I'll be the first to admit it (the guy sitting next to me will be the second). :)
How should I make use of the 'window.onload = self.print();' syntax you suggest, theboyhope ?
Control-wise, I'm dealing with a TextBox from the Visual Studio ASP.NET pallet.
Any further suggestions ?
Thanks so far .....
Steve
 
How should I make use of the 'window.onload = self.print();' syntax you suggest, theboyhope ?

I'm not sure which part it is you didn't understand ...
 
theboyhope - surely the 'self.print()' will print the contents of the whole document (web page) ?
Rather than just the TextBox I require.
That's the part I don't understand. :(
I want to only deal with the contents of a specific TextBox rather than everything on the web form.....

Thanks again.
Steve
 

Why not have a print style sheet which instructs every element (except the textbox) to not print?

Hope this helps,
Dan
 
I guess the suggestions so far make perfect sense to those in the know. :(
I want to specifically print (or save) the contents of a single TextBox.
Where (and how) do I make use of a print style sheet ?
Thanks again.
Steve
 
surely the 'self.print()' will print the contents of the whole document (web page) ?
Which is why I suggested transferring the contents of the textarea into a new popup window and printing that.

Don't see any problem with the print stylesheet idea either though.
 

If you have this in your head section:

Code:
<link rel="stylesheet" href="normal.css" type="text/css" media="screen, projection, tv" />
<link rel="stylesheet" href="print.css" type="text/css" media="print" />

and you have your normal CSS in "normal.css" and the following in "print.css":

Code:
* {
   display: none;
}
textarea {
   display: block;
}

then that should give you your standard layout on screen, but when printing, everything except textboxes will be hidden.

And you could go one stage further, and use classes instead... So this in your print CSS:

Code:
* {
   display: none;
}
.printThis {
   display: block;
}

would print only elements that had a class of "printThis".

Hope this helps,
Dan
 
BillyRayPreachersSon - This is looking like it's heading me in the right direction. :)
To add insult to injury, I'm already making use of stylesheets against the TextBox (which is the only component I want to print / save contents of).
Am I able to work your idea into the existing stylesheet or can I reference two style sheets when dealing with the 'CssClass' against the neccessary TextBox ?
Thanks so far everyone,

Steve
 

You can have both multiple style sheets on a page, and multiple classes on an element. So if your textbox already has a class:

Code:
<textarea class="wibble">...</textarea>

then you can add another one by separating them with spaces:

Code:
<textarea class="wibble bibble">...</textarea>

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top