Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing random quote display to sequential 1

Status
Not open for further replies.

suoiduts

Technical User
Mar 17, 2008
2
I have a site that currently uses JavaScript to randomly display a quote from an array of quotes each time the page is loaded. However, since this often results in the same quote being displayed several times in a row, I have decided that I would rather just cycle through the quotes in the array sequentially rather than randomly. Unfortunately, I don't know how to do this and I can't seem to find any sample code that will point me in the right direction. Any suggestions?
 
You could look into using a cookie. Set the value of the cookie on initial visit to the site, then increase the value of the cookie for each page load - and use that as the index for your array lookup. You can use the mod (%) operator to ensure you don't go out of bounds.

Do some research, try some stuff for yourself... and come back if you have any problems.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks Jeff, a cookie was the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top