using rollover images in repeat regions

 

if you use the "Swap Image" behaviour within a repeat region it will not work. the reason becomes clear when you have a look at the code around the image and understand how it works:

<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('image1','','my2nd.gif',1)"><img src="my1st.gif" width="219" height="121" name="image1" border="0"></a>

the JavaScript that makes the rollover work addresses the image object by it's name and swaps the src property. in order to function properly the image needs to have an unique name. if you simply apply a repeat region to it the code will look like the following:

<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
...
<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('image1','','my2nd.gif',1)"><img src="my1st.gif" width="219" height="121" name="image1" border="0"></a>
...
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>

since the image name is not made dynamic you create several images with the same name. therefore the rollover fails.

solution:

Ultradev provides an unique parameter to move through the records. you can use this parameter to make the image name dynamic (unique) like the following:

<%
dim vimg
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
vimg = "img" & cstr(Repeat1__index)
%>
...

<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('<%= vimg %>','','my2nd.gif',1)"><img src="my1st.gif" width="219" height="121" name="<%= vimg %>" border="0"></a>

...
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>

make sure that you always use some letters at the beginning of your image names, never just
vimg = cstr(Repeat1__index) since this results in invalid image names. to find out more about image names see Macromedia technote 13282

 

 


 

1