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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select & Print a specific DIV

Status
Not open for further replies.

daveh

Technical User
Jun 22, 2000
57
GB
Hi,

I have a page made up of <div>'s and I want to have a link selects and prints only the DIV. I am assuming here it is possible for a bit of javascript to select the contents of a DIV on the page, and then to launch the "print selection" dialog box, so that the user only needs select the print and click OK.

Thanks for your help in advance,
David.
 
You could create print media styles for printing the page, but that will alienate each page to only one div, unless you had the media styles declared dynamically. What I would suggest as being the easiest way is to open a new window with the div content and print from that window.

-kaht

Do the chickens have large talons?
 
you'll need to use javascript along with css. rather than write imaginary code for you to say doesn't work with your scenario, could you post your page source so we can assist you better?

thanks.

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hi, thanks for your comments so far. Unfortunately I am unable to post the page source as it is commercially sensitive, and would take me ages to strip it of the content whilst leaving the key structure the same.

However, some pieces of info...

- Due to the content manager tool being used to produce/publish the page, I am unable to edit the <head> content, or anything in the <body> tag. Within the body I can post whatever HTML I want.
- I can put any javascript/css in, but it can't appear in the <head> section of the page.
- The page has a large <div name="results">, inside which there is a table, each row having an ID, which is hidden or displayed depending on the results of some javascript. The row's are hidden/displayed using document.all.rowid.style.display='';.

What I want is a piece of text where the online automatically displays whatever is displayed on the screen within that DIV and prints it.

Thanks for your help.
Dave.
 
In this case you want everything inside of the div printed. Can you encapsulate everything else on the page inside of another div? Or perhaps 2 divs if you have content above and below? Something like this is possible if so:
Code:
<html>
<head>
<style>
@media print {
   .noprint {display:none}
}
</style>
</head>
<body>
<form name=blahForm>
<div class=noprint>
all the material above what you want printed
</div>
<div>
all the material that is to be printed
</div>
<div class=noprint>
all the material below what you want printed
</div>
</form>
</body>
</html>
If this won't work for you then I don't know what else to suggest. (this is by far the easiest route)

-kaht

Do the chickens have large talons?
 
Thanks for your comments - I think we have our wires crossed here, for which I apologise.

I have already got the different parts of the page (ie. DIVs) displaying correctly. I want to be able to print a certain DIV... as in print it to an external paper printer. I want them to click on a bit of text and for it to bring up the print dialog box to bring the div named "results".

Dave.
 
Oh right excellent, me being rather ignorant there then. So if I invoke a normal print from the page using javascript, how do I get it to print only that? Does it print that automatically? If I just do a window.print will that print the correct thing?

Apologies that I can't be more helpful but this problem is at work, and I can't try it out till I'm in tomorrow morning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top