How do I make a simple scrolling text box in JavaScript

I have a project where we need to make a small box that vertically scrolls through a number of customer testimonials. I'm not sure scroll is the appropriate word, as I need basically one testimonial to be up, and after seven seconds, it switches to the next testimonial. I have an HTML document with all the testimonials written out and seperated by divs. I also don't want the testimonial text to be within my main html page, so I need to reference it from another HTML document.

So, is there a way to have these testimonials switch from one to the next based off divs? Thanks for the help, and I hope this was clearly communicated. This is my first posting.
VanStoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

numberkruncherCommented:
How about something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Demo Page</title>
		<style type="text/css">
			/* Use CSS to control visibility */
			div.testimonial {
				display: none;
			}
			div.testimonial.active {
				display: block;
			}
		</style>
		<script type="text/javascript">
			var activeTestimonial = 0, testimonialCount = 0;
			function onLoad() {
				/* Initialize count and timer. */
				updateTestimonail();
				var seconds = 5; // Every 5 seconds...
				setInterval(onTick, seconds * 1000);
			}
			function onTick() {
				/* Move to next testimonial and update. */
				++activeTestimonial;
				/* Wrap back to first one! */
				if (activeTestimonial >= testimonialCount)
					activeTestimonial = 0;
				updateTestimonail();
			}
			function updateTestimonail() {
				var el = document.getElementById('testimonials').firstChild;
				testimonialCount = 0;
				/* Count testimonials and add 'active' to class name. */
				while (el) {
					if (el.tagName == 'DIV') {
						if (testimonialCount == activeTestimonial)
							el.className = 'testimonial active';
						else
							el.className = 'testimonial';
						++testimonialCount;
					}
					el = el.nextSibling;
				}
			}
		</script>
	</head>
	<body onload="onLoad();">
		<h1>Demo Page</h1>
		<div id="testimonials">
			<h2>Testimonial</h2>
			<div class="testimonial">Great stuff!</div>
			<div class="testimonial">Excellent!</div>
			<div class="testimonial">Recommended!</div>
		</div>
	</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scrathcyboyCommented:
"So, is there a way to have these testimonials switch from one to the next based off divs?"

Sure, but you don't have to have the DIV code in the other file.  You could simply have a DIV structure in the main file, and then a simple javascript array of the various testimonials, separated by "Quote" and new line.  

Then the javascript just reads the next testimonial into the DIV layer (all you need is a name and ID for it) based on a timer.  That is how I would do it, and the text file for the testimonials would be a simple javascript array.  Can give an example if you want.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.