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

Java Script Help

Status
Not open for further replies.

mayfair

Programmer
Jun 29, 2001
12
US
I have a java script that finds a random number, than with that number prints out the picture in that array spot. Here is the code

<script language=&quot;JavaScript&quot;>
<!-- Hide from old browsers
function random_imglink()
{
var myImages=new Array()
var myComments=new Array()
//specify random images below. You can have as many as you wish

myImages[1]=&quot;images/yuma.jpg&quot;
myComments[1]=&quot;Sunrise in Yuma, AZ&quot;

myImages[2]=&quot;images/odell1.jpg&quot;
myComments[2]=&quot;Marlene Kohanes &amp; Husband on Odell Lake&quot;

myImages[3]=&quot;images/greghickman.jpg&quot;
myComments[3]=&quot;Greg Hickman&quot;

myImages[4]=&quot;images/mount_hood.jpg&quot;
myComments[4]=&quot;Mount Hood Oregon&quot;

myImages[5]=&quot;images/Multnomah_Falls.jpg&quot;
myComments[5]=&quot;Multnomah Falls Oregon&quot;

myImages[6]=&quot;images/Oregon_Beaches.jpg&quot;
myComments[6]=&quot;The Oregon Beaches&quot;

myImages[7]=&quot;images/Crater_Lake.jpg&quot;
myComments[7]=&quot;Crater Lake at Sunset&quot;

myImages[8]=&quot;images/Light_House.jpg&quot;
myComments[8]=&quot;Light House on a Oregon Beach&quot;

myImages[9]=&quot;images/diamond_falls.gif&quot;
myComments[9]=&quot;Diamond Falls Oregon&quot;

myImages[10]=&quot;images/silver_falls.gif&quot;
myComments[10]=&quot;Silver Creek Falls Oregon&quot;

myImages[11]=&quot;images/mt_st_helens.gif&quot;
myComments[11]=&quot;Mount Saint Helens Washington&quot;

var ry=Math.floor(Math.random()*myImages.length)
if (ry==0)
ry=1
document.write('<img src=&quot;'+myImages[ry]+'&quot; ALIGN=RIGHT alt=&quot;'+myComments[ry]+'&quot;>');
}
random_imglink()
// -- End Hiding Here -->
</script>

The problem is that in Netscape 4.5, when I do print preview nothing shows, but when I take out the entire Java Script the whole page will print preview and print out fine. Any seggestions?
 
i guess that when you print preview, the page is NOT processed, meaning javascript is NOT executed either, that's why nothing shows up !
 
but the page loads and gets a random picture shown on it? I tested this some more and when every I use a document.write in the body of a web page the print preview doesn't work, but when I do it in the head, it works. Any thoughts?
 
yes
if you do it in the header, it's BEFORE the page is loaded - whereas in the body it's done AFTER the page is loaded
the print preveiw (i think) shows the page as it was when it is loaded - so if you change the page after loading, the changes won't appear on the print preview - unless you make the user save the page and then print the SAVED page (not the actual one)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top