Forum Moderators: open

Message Too Old, No Replies

Using div to print section of webpage

         

InquisitorX

7:21 pm on Jul 15, 2003 (gmt 0)

10+ Year Member



From this post it says I can learn how to print out a section of a web page using a <div> tag.
[webmasterworld.com...]

The thing is, I just get the ever loving Object does not support this property or method error.. Where am I going wrong?

<script type="text/javascript">
<!-- //

function printthis(which) {
document.getElementByTagName('div').style.display = 'none';
document.getElementById(which).style.display = 'block';
window.print();
document.getElementByTagName("div").style.display = 'block';
}
//-->
</script>
<a href="javascript:void printthis('Week28');">Print</a>

<div id="Week28" style="display: block">Mooo</div>
<div id="Week29" style="display: block">Bahhh</div>
<div id="Week30" style="display: block">Bahhh</div>

InquisitorX

8:11 pm on Jul 15, 2003 (gmt 0)

10+ Year Member



Bwhahahahah! I found the error(s)..
The first one was >document.getElementByTagName<... IS WRONG!

it is >document.getElementsByTagName< Notice it is Elements, not Element.

Then I just had to go throught all the elements :)

<script language="javascript1.2">
function printthis(which) {
var tds = document.getElementsByTagName("div");
for(i=0;i<tds.length;i++)
tds.item(i).style.display = "none";
document.getElementById(which).style.display = "block";
window.print();
for(i=0;i<tds.length;i++)
tds.item(i).style.display = "block";
}
</script>

<input type="button" onclick="printthis('Week32')" value="CLICK Me">
<div id="Week32">OINK</div>
<div id="Week32">Cluck</div>

Does the geek victory dance :)