Re: [NigelGordijk] Random table cell background image
Hi Nigel,
Just to clarify, you're referring to having a section in CMS Builder where you store your different images and then having those images put into your javascript dynamically. Is that right?
If so, you can do something like this. In this example, I'm assuming your using a single record section called "randomImages" and that section has an upload field called "images".
First, we get our image records like this:
<?php
list($randomImageRecord, $randomImageMetaData) = getRecords(array(
'tableName' => 'randomImages',
'limit' => 1,
'allowSearch' => false,
));
$images = array();
if ($randomImageRecord) {
$images = $randomImageRecord[0]['images'];
}
?>
Then you can output these images into your javascript like this:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
var image = new Array();
<?php $counter = 0; ?>
<?php foreach ($images as $image): ?>
image[<?php echo $counter++; ?>] = '<?php echo $image['urlPath'];?>' ;
<?php endforeach ?>
var index = Math.floor(Math.random() * image.length);
document.write('<style type="text/css"> td.title { background-image: url('+ image[index] +') } </style>');
//-->
</SCRIPT>
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/