/    Sign up×
Community /Pin to ProfileBookmark

Print section of data function

Hello,

I’m creating a page that has different blocks of data and i want the user to be able to click a tag and print that portion of data only.

I currently have 2 stylesheets, Index.css & Print.css

I’m not sure if i should try this another way, but i feel like i’m headed in the right direction. Using IE btw.

Something similar to this..

[code]
<head>
<link href=”Index.css” rel=”stylesheet” type=”text/css”/>
<link href=”Print.css” rel=”stylesheet” type=”text/css” media=”print”/>
<script language=”JavaScript”>
function printThis(s,d) {
var sheet = document.styleSheets[1];
sheet.addRule(s,d);
window.print();
}
</script>
</head>

<body>
<div id=”section1″><a href=”Javascript:printThis(‘body div#section2′,’display:none’)”>Print me</a>
</div>

<div id=”section2″><a href=”Javascript:printThis(‘body div#section1′,’display:none’)”>Print me</a>
</div>

</body>
[/code]

I think if i get this simpler portion of code to work correctly, i could get everything else to work out. I’m just stuck. Anything i’m doing wrong?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@pupauthorMay 25.2012 — Seem to work ok in chrome.. But thats all.
Copy linkTweet thisAlerts:
@pupauthorMay 29.2012 — bamp.

Alternate code that isn't quite working like i want...

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;style type="text/css" media="print"&gt;
div {
display: none;
}
.print {
display: block;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
function cheeseburger(juicy) {
document.getElementById(juicy).style.className="print";
window.print();
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="section1"&gt;
&lt;h1 onClick="cheeseburger('section1')"&gt;PRRRRIIINNNNTTTTTEEEEERRRRR&lt;/h1&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div id="section2"&gt;
&lt;h1 onClick="cheeseburger('section2')"&gt;PRINT MACHINE!!!!!one!!&lt;/h1&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @pup spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...