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

How can I link different Images in my banner?

Status
Not open for further replies.

JrClown

Technical User
Oct 18, 2000
393
US

[tt]Could anyone please advise me on how to make my 5 images link to specific locations of our website? Thanks in avance, here's my code[/tt]

[tt]
<script LANGUAGE=&quot;JavaScript&quot;>
<!--Hide

var numImages = 5
var allImages = new Array(numImages)
var i = 0
allImages[0] = new Image()
allImages[0].src = &quot;image1.gif&quot; 'Should go to Yahoo.com
allImages[1] = new Image()
allImages[1].src = &quot;image2.gif&quot; 'Should go to MSN.com
allImages[2] = new Image()
allImages[2].src = &quot;image3.gif&quot; 'Should go to Hotmail.com
allImages[3] = new Image()
allImages[3].src = &quot;image4.gif&quot; 'Should go to Disney.com
allImages[4] = new Image()
allImages[4].src = &quot;image5.gif&quot; 'Should go to CDNow.com

function nextImage() {
document.images[0].src = allImages.src
i = i + 1
if (i>=numImages)
{
i = 0
}
setTimeout(&quot;nextImage()&quot;, 4000)
}
setTimeout(&quot;nextImage()&quot;, 4000)
//Stop Hiding-->
</script>

[/tt]



&quot;The reward of one duty done is the power to fulfill another&quot;
J R C L [jester] W N


 
[tt]Actually is not a banner, I'm simply rotating 5 separate images with different quotes on them refering to what our company does and would like to link each quote to each department page.[/tt]

&quot;The reward of one duty done is the power to fulfill another&quot;
J R C L [jester] W N


 
Try:

<script language=&quot;javascript&quot;>
var img=new Array('image0.gif,'image1.gif','image2.gif');
var lnk=new Array('link0.htm','link1.htm','link2.htm');
var imgindex=0;

setInterval(changeimage(), 2000);

function changeimage()
{
imgindex++;
imgindex %= img.length;

document.images['imgname'].src=img
;
}

function changepage()
{
location.href=lnk
;
}

</script>

<img name=&quot;imgname&quot; onclick=&quot;changepage();&quot; src=&quot;image0.gif&quot;>
 
I use objects myself for this kind of thing, but the simplicity of objects means learning something more complex. Unfortunately, most JS programmers don't take advantage of objects to make things easier to use. I think that most people who use JS don't use it enough to think in OOP.
 
[tt]Thanks trollacious[/tt]

[tt]BTW xutopia, why isn't there a reference to on your site? Just curious.[/tt]



[tt]trollacious, I'd would give you a fat
star.gif
but you're a visitor bro. [/tt]


&quot;The reward of one duty done is the power to fulfill another&quot;

Jr Cl[atom]wn

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top