Log in

View Full Version : Dynamic Content



sukid13
03-26-2008, 03:12 AM
Hi, i'm I have about 15 random testomonials that I want to incorporate into my website. I have made a div and put one testimonial inside it. However, I was hoping there would be a way to randomly put a different testimonial on my page every time the page is refreshed. Thankyou for your help.

codeexploiter
03-26-2008, 03:23 AM
Try the following code



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title> </title>
<style type="text/css">

</style>
<script type="text/javascript">
//Store your testimonials in the following array.
var testimonials = [
"Testimonial 1",
"Testimonial 2",
"Testimonial 3",
"Testimonial 4",
"Testimonial 5",
"Testimonial 6",
"Testimonial 7",
"Testimonial 8",
"Testimonial 9",
"Testimonial 10",
"Testimonial 11",
"Testimonial 12",
"Testimonial 13",
"Testimonial 14",
"Testimonial 15"
];


window.onload = function(){
document.getElementById("testimonialEl").innerHTML = testimonials[Math.floor(Math.random()*testimonials.length)];
}
</script>
</head>
<body>
<div id="testimonialEl"> </div>
</body>
</html>