Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to make a random image appear on a page using Javascript

Explorer ,
May 16, 2013 May 16, 2013

I've got an array of eleven images that I wish to show randomly on the index page in a site.  The image should change with every visit to the page.  I've tried various javascript "solutions" I've found on line, but none seem to work.  I've got the array in the head, with the complete path to the image on each element. 

How do I randomize the display, and how do I cause the image to appear in the div I've got set for the image?

Gene

TOPICS
Server side applications
822
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2013 May 16, 2013

If you've tried various solutions and none have worked, then we need to figure out what you are doing wrong. Can you post the code that you have tried?

By the way, this forum is for server side applications, not client side.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 16, 2013 May 16, 2013

Well, since I'm putting as much in the head as possible, it will be done serverside, I believe.  If I'm wrong, I apologize.  I can't post the code because the three examples I got off the internet do not work at all.  There's a page up on our server now that has the code as it sits, but that's only the array there. 

So, I'll go look elsewhere.

Gene

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 17, 2013 May 17, 2013
LATEST

>Well, since I'm putting as much in the head as possible, it will be done serverside, I believe.

I'm not sure what you are trying to say here. Using a server side solution is a matter of inserting server side code, not how much code you are putting in the head. Image rotation can be done with either client or server side code.

>I can't post the code because the three examples I got off the internet do not work at all.

You can't post the code that isn't working? Why not?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines