I'm looking for a snippet of code that would let me generate testimonials, quotes or any string value randomly on a webpage. I would like for it be standards compliant, XML based(meaning I would store the testimonials in an xml file), and the less obtrusive it is, the better.

Where could I download such a thing or is there an example out there? I pretty much googled around, but had no luck. Also, I tried modifying the Ajax Ticker seen here:

http://www.dynamicdrive.com/dynamicindex17/rsstickerajax/index.htm


If you want to attempt to solve this on your own instead of providing me a link, here's what I got:

I have a div tag in my body tag with the id 'testimonials' with this javascript code inside it:

<script type="text/javascript">

var xmlfile="tickercontent/ticker_office.txt" //path to ticker txt file on your server.

//ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
new ajax_ticker(xmlfile, "ajaxticker1", rotate() )
</script>

That just basically establishes where the xml file is located and loads it with the external javasript file and my function which is inside that ext javascript file called "rotate()"


inside that "rotate()" function, I have code similar to this:

var randomizeMessage= xmldata

var randomizedTicker = math.random(randomizeMessage)

document.getElementById("testimonials").innerHTML = randomizedTicker


Any idea how I could load what's inside a class called "message" (which would be in a external xml file) into a webpage randomly?

hmmm i dont know. just cam in to know about the answerr n i think it can work i'll surely try itt

Let me know if my post was too wordy. I can try to simplify it for you guys if you want? or how could I take this code that I just written and set the array to equal whats in a div tag with the id of 'messages' and it's in a XML file? I can imagine it's some sort of javascript import feature, how do I get data from an XML file?:

<html>
<head>
	<script type="text/javascript">



		var testimonials = ["My first quote", "hello", "sfsasfasfasfs" , "adfasdfs" , "Q5" , "Q6" , "Q7" , "Q8" , "Q9" , "Q10" , "Q11" , "Q12" , "Q13" , "Q14" , "Q15"];


		function getRandomTestimonials(){
		numberOfTestimonials = testimonials.length;
		randNum = Math.floor(Math.random()*numberOfTestimonials);
		return testimonials[randNum];
		}


	</script>

</head>


<body>

	<div id="testimonials">
		<script type="text/javascript">
		document.write(getRandomTestimonials());
		</script>
        </div>


</body>
</html

swaters86 Thank you for the script but I want it to be change automatially every 5 second or have a next and previous link to display seperate testimonial.

Thanks for the info:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.