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

?? on placement of random image

Status
Not open for further replies.

leTigre

Programmer
Mar 26, 2003
13
0
0
US
Hi, I'm using the following code to place a random image with links:

<script language=&quot;JavaScript&quot;>
function random_imglink(){
var myimages=new Array()

myimages[1]=&quot;/Homepage/images/mainFrame_Beth_01.gif&quot;
myimages[2]=&quot;/Homepage/images/mainFrame_Darla_01.gif&quot;
myimages[3]=&quot;/Homepage/images/mainFrame_Natalie_01.gif&quot;
myimages[4]=&quot;/Homepage/images/mainFrame_Toni_01.gif&quot;
myimages[5]=&quot;/Homepage/images/mainFrame_Twins_01.gif&quot;
myimages[6]=&quot;/Homepage/images/mainFrame2_01.gif&quot;
myimages[7]=&quot;/Homepage/images/mainFrame_Vivian_01.gif&quot;


var imagelinks=new Array()
imagelinks[1]=&quot;/MainFrame/mf_PS_Beth.htm&quot;
imagelinks[2]=&quot;/MainFrame/mf_PS_Darla.htm&quot;
imagelinks[3]=&quot;/MainFrame/mf_PS_natalie.htm&quot;
imagelinks[4]=&quot;/MainFrame/mf_PS_Toni.htm&quot;
imagelinks[5]=&quot;/MainFrame/mf_PS_twins.htm&quot;
imagelinks[6]=&quot;/MainFrame/mf_PS_laPorscha.htm&quot;
imagelinks[7]=&quot;/MainFrame/mf_PS_Vivian.htm&quot;

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'&quot;'+imagelinks[ry]+'&quot;'+'><img src=&quot;'+myimages[ry]+'&quot; border=0 ></a>')
}
random_imglink()
//-->
</script>


I would like the random image to appear in a specific spot on a sliced page. Should I use an image placeholder, a named anchor, or ?? Could you please post the code for this, too, b/c I'm not very swift with the coding bit. Thanks to anyone who can help!
 
first things first... the FIRST element in an array is [0] not [1]...
that will put 7 things in each array.. the last one being [6]...
okay, so you have your arrays set up for the links and the images... in the html do this...
<img src=&quot;&quot; id=&quot;randomimg&quot;><br>
<a href=&quot;&quot; id=&quot;randomlink&quot;>Click Here</a>

and then after all your array stuff do this...
var imgrand=Math.random()*10;
var linkrand=Math.random()*10;
var imgnum=Math.round(imgrand);
var linknum=Math.round(linkrand);

if (imgnum>6 || linknum>6){
random_imglink();}
else {
document.getElementById('randomimg').src=myimages
;
document.getElementById('randomlink').href=imagelinks[linknum];
}

HOPE THAT HELPS





Later,
Greelmo
 
Actually, the random image will change each time the page is visited, so there is no button to &quot;click here&quot;. I don't want to change it into a totally new javascript. I'd just like to add a way to identify an image placeholder for it to load into. Is there a way I could do it that way? Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top