View Full Version : Newbie, please help?

11-07-2008, 11:12 AM
Quick questions, and im sure its an easy one to sort.

Basically, on my current site, i have put section on the index page for a testimonial to appear. I want to know if i can say pre enter 10 testimonials so that only one appears on the page, but will randomly change to another of the 10 when the page is refreshed, or when a different page is visited?

Can anyone help?

Many thanks
Dan Almond

11-07-2008, 01:23 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function randomiser(){
var stuff = new Array();
stuff[0] = "text 1"; /// << array value - add your own text
stuff[1] = "text 2"; /// << array value - add your own text
stuff[2] = "text 3"; /// << array value - add your own text
stuff[3] = "text 4"; /// << array value - add your own text
stuff[4] = "text 5"; /// << array value - add your own text
/// << array value - add new array and text

i = parseInt(Math.random() * 5); /// <<< change the 5 to the array count above
document.getElementById('randomText').innerHTML = stuff[i];
<body onload="randomiser()">
<!--***** place where you want the text to appear in your HTML -->
<div id="randomText"></div>
<!-- ///////////////////////////////////////////////////////// -->

11-07-2008, 04:47 PM
Hello Dan,

I was just curious. Are your pages static html pages or are they php?

If php you may want to use a php script for this over js.

11-07-2008, 05:32 PM
Just did this on a recent project.. pretty much what DJ suggested, in a seperate .js file.