This zone is sleeping right now! ZzzZZzzz

Better not distrub it! ~You go to the petrol station and buy a slushy instead, everything is cool!~

This area will open again in 000.beats!

(Learn about Swatch Time)

Some other zones are awake :^]


Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
June 08, 2026 - @583.18 (what is this?)
Activity rating: Four Stars Posts & Arts: 60/1k.beats Random | Recent Posts | Guild Recents
News: :cry: Are u having fun? Guild Events: Happy Pride Month Fibre Artists!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  Randomized elements that change upon refresh?


« previous next »
Pages: [1] Print Embed
Author Topic: Randomized elements that change upon refresh?  (Read 946 times)
KatiePla.net
Jr. Member ⚓︎
**
View Profile WWW


Hey you, backup your files! Yes, do it NOW!
⛺︎ My Room
StatusCafe: katieplanet

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

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

     https://katieplanet.neocities.org/ForumPosts/fruit.png

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 ⚓︎
*
View Profile WWW


I can't be sure of anything
⛺︎ My Room

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

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

https://web.archive.org/web/20090901193917/http://geocities.com/nikoanime/whale.gif
xwindows
Full Member
***
View Profile


⛺︎ My Room

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

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 Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ 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
MelonLand @000

Minecraft: Online
Join: craft.melonking.net