Entrance Chat Gallery Guilds Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
August 16, 2025 - @736.44 (what is this?)
Activity rating: Four Stars Posts & Arts: 52/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :skull: Websites are like whispers in the night  :skull: Super News: Upload a banner! (or else!)

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  Randomized elements that change upon refresh?


« previous next »
Pages: [1] Print
Author Topic: Randomized elements that change upon refresh?  (Read 276 times)
KatiePla.net
Jr. Member
**


Hey you, backup your files! Yes, do it NOW!

⛺︎ My Room
StatusCafe: katieplanet

View Profile WWW

tamanotchi enthusiast!Under Construction Gif ProviderJoined 2024!
« on: April 06, 2025 @64.62 »

Hi everyone!

Y'all may have seen a few previous posts of mine looking for retro ads to add to my website, and thanks to all the awesome contributions y'all have made, I have a great collection of ads I'd love to add to my site.  :ha:

As for their implementation, I'd love for them to be randomized, with a different ad showing on each refresh. I am not sure how to code this, however I'd love to learn! If anyone has any advice or direction on how to code a randomized element, I'd really appreciate it.

Thank you!  :transport:
Logged

    

World's #1 Tamanotchi Fan - Please feed DJ★Starr!! (He likes fruit!)

DJ★Starr says..."Backup your favorite files NOW, there is no better time than today! Always support the best option for the world, not the most likely one! Going vegan is really worth considering - modern animal agriculture is terribly cruel. You are so unique and needed in this world - never be afraid to shine your true light! You are always allowed to change, and you're capable of incredible transformation! Trans rights are human rights! Be brave."
P_quod
Newbie ⚓︎
*


I can't be sure of anything

⛺︎ My Room

View Profile WWW

Joined 2025!
« Reply #1 on: April 09, 2025 @576.78 »

Hiya!

Well, I don't know if it would be the easiest solution for you if you're not familiar with the language, but I'd use some javascript to do what you describe.

To make it quick, I would:

- Create an array with all my images src
Code
let myArray = ["my-first-image-src", "my-second-image-src", "etc"]
- Create a function that picks a random src in that array and fills my image src with it. Something like that:
Code
function randomImg(){
let randomNumber = Math.floor(Math.random() * myArray.length);
let randomImg = myArray[randomNumber];
document.getElementById("the-id-of-my-img-div").src = randomImg;
}
- Call the function when my page loads
Code
window.onload = randomImg()

I googled "display random image onload javascript" and one of the first entries looks like it would do the job (and maybe it would offer you a better explanation than mine!)

Hope this answer will be helpful  :seal: 
« Last Edit: April 09, 2025 @583.46 by P_quod » Logged

xwindows
Full Member
***


⛺︎ My Room

View Profile

Great Posts PacmanJoined 2024!
« Reply #2 on: April 13, 2025 @498.68 »

Half a year ago, someone asked for a very similar thing; which I answered with several solutions, both server-side and client-side-- each approach outlined with detailed requirements and tested conditions. You might want to take a look.
Logged
Pages: [1] Print 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi