Results 1 to 2 of 2

Thread: Dynamic Content

  1. #1
    Join Date
    Mar 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Content

    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.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following code

    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>
    Last edited by codeexploiter; 03-26-2008 at 03:27 AM. Reason: code correction

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •