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

Image Swap Behavior

Status
Not open for further replies.

danielh68

Technical User
Jul 31, 2001
431
US
Hi,

I want to create an image swap, like the one at . Basically, each visit the page reloads displaying a new picture.

To begin, I snagged the code from their site and replaced their images/paths with my own...it didn't work.

So, I opened DW and said "hey..maybe there's a behavior". Well, there is, but I can't seem to get it to work. Here's what I do:

1.insert an image
2. select the swap behaviour
3. in the little that appears, select you current image, then browse and select the other image
4. If I have it set for mouse over, it works fine, however if it's set on onLoad I get a stack overlay error.

Any advice? I can post it if neccessary.

Thanks in advance,
DanH
 
that actually is a random image display...you can find a javascript code for it where your page would display a random image on load.

[afro] sometimes i just cant take it...then i realize its already to late
 
Thanks, deecee. What I don't understand is this: in theory, I should be able to copy the javascript code off the dell page, insert it in my own table, replace their paths&images with my own and it should work, right?

Thanks,
Dan
 
in theory yes unless they are targeting an external javascript file sometimes i just cant take it...then i realize its already to late
 
WHy you want to use onload event for image swap. You can use onclick or onmouseover for the same.
 
year2000,

I just want the images to swap whenever the page is refreshed. I don't want the images to swap on a mouseover or onclick. If you go to and refresh you will notice the image changes. Currently, I'm using a javascript to accomplish this, but it's a tad unpredictable. It works, just not consistently.

Thanks for you interest.
DanH
 
Out of curiousity I tried it...it worked for me. I hope this helps you:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<table width=&quot;50%&quot; border=&quot;0&quot;>
<tr>
<td>
<script language=&quot;JavaScript&quot;><!--
var src = new Array();
var href = new Array();
var img = new Array();
var i_caption = new Array();
src[0] = &quot;urgraphic_here.jpg&quot;;
img[0] = new Image;
img[0].src = src[0];
href[0] = &quot;whereyouwanttogo.htm&quot;;
i_caption[0] = &quot;text_for_mouseover&quot;;
src[1] = &quot;another.jpg&quot;;
img[1] = new Image;
img[1].src = src[1];
href[1] = &quot;whereyou_wantthelink_togo.html&quot;;
i_caption[1] = &quot;change text here&quot;;
src[2] = &quot;another.jpg&quot;;
img[2] = new Image;
img[2].src = src[2];
href[2] = &quot;whereyouwanttogo.htm&quot;;
i_caption[2] = &quot;yet some more text&quot;;
src[3] = &quot;graphichere.jpg&quot;;
img[3] = new Image;
img[3].src = src[3];
href[3] = &quot;whereyouwanttogo.html&quot;;
i_caption[3] = &quot;mouseovertext&quot;;
src[4] = &quot;another.jpg&quot;;
img[4] = new Image;
img[4].src = src[4];
href[4] = &quot;whereyouwanttogo.com&quot;;
i_caption[4] = &quot;Visit the new Steven site and see his new commercial.&quot;;
src[5] = &quot;anotherimage.jpg&quot;;
img[5] = new Image;
img[5].src = src[5];
href[5] = &quot;whereyouwanttogo.htm&quot;;
i_caption[5] = &quot;somemoretext&quot;;
var dt = new Date();
var cycle = Math.floor(Math.random() * 6);
if( href[cycle] != null ) {
document.write( &quot;<A HREF=\&quot;&quot; + href[cycle] + &quot;\&quot;><IMG SRC=\&quot;&quot; + src[cycle] + &quot;\&quot; alt=\&quot;&quot; + i_caption[cycle] + &quot;\&quot; WIDTH=458 BORDER=0></a>&quot; );
}
else
{
document.write( &quot;<IMG SRC=\&quot;&quot; + src[cycle] + &quot;\&quot; WIDTH=458>&quot; );
}
//--></script>
<noscript> <a href=&quot;edithere.htm&quot;><img src=&quot;train.jpg&quot; border=&quot;0&quot; /></a></noscript>
</td>
</tr>
</table>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top