User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 429,776 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,893 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 702 | Replies: 2
Reply
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

Random Testimonial Generator

  #1  
Jul 10th, 2008
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2008
Posts: 20
Reputation: tecktalk is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
tecktalk tecktalk is offline Offline
Banned

Re: Random Testimonial Generator

  #2  
Jul 11th, 2008
hmmm i dont know. just cam in to know about the answerr n i think it can work i'll surely try itt
Reply With Quote  
Join Date: Jul 2007
Posts: 25
Reputation: swaters86 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
swaters86 swaters86 is offline Offline
Light Poster

Re: Random Testimonial Generator

  #3  
Jul 11th, 2008
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

Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC