PDA

View Full Version : Newbie, please help?


dan_almond
11-07-2008, 12:12 PM
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

davidj
11-07-2008, 02: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">
<head>
<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];
}
</script>
</head>
<body onload="randomiser()">
<!--***** place where you want the text to appear in your HTML -->
<div id="randomText"></div>
<!-- ///////////////////////////////////////////////////////// -->
</body>
</html>

coloeagle
11-07-2008, 05: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.

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