Web Development



Random Image Background within a HTML Table cell td

By martinbullock15 ·

I am trying to make it so each time a customer enters a page the background image of a certain cell (td) will change.

I have searched and tried many different suggestions with no luck. The website is template driven therefore on the page in question there are no head or body tags.

this is what i have tried so far,

This was placed at the top of the code:

<script language="JavaScript" type="text/javascript"><!--

var image = new Array();

image[0] = '/images/<!-- TMPL_VAR NAME=site -->/dept_header_<!-- TMPL_VAR NAME=dept_id -->.jpg' ;

image[1] = '/images/<!-- TMPL_VAR NAME=site -->/dept_header_<!-- TMPL_VAR NAME=dept_id -->a.jpg' ;

image[2] = '/images/<!-- TMPL_VAR NAME=site -->/dept_header_<!-- TMPL_VAR NAME=dept_id -->b.jpg' ;

image[3] = '/images/<!-- TMPL_VAR NAME=site -->/dept_header_<!-- TMPL_VAR NAME=dept_id -->c.jpg' ;

var index = Math.floor(Math.random() * image.length);

The image root is determined on the ID of the site and the ID of the current page, i know that these paths work as i have copied the paths from another section.

This was then place instead of the td tag

document.write('td colspan="3" background="+ image[index] +"/td');

With < and > included (but for some reason they weren't listed correctly in this post)

Any suggestion would be very gratful if more code is required let me know

Kind Regards


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums