/    Sign up×
Community /Pin to ProfileBookmark

Show a set of images in a random order

I have a set of 9 images – I want them to load in a random order whenever the page reloads.

ie 1,2,3,4,5,6,7,8,9

then 2,5,3,7,4,8,6,1,9 etc

Any ideas if/how this can be done?

Many thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mrhooNov 28.2009 — [CODE]onload= function(){
var n, pic,
A= [1, 2, 3, 4, 5, 6, 7, 8, 9];// replace integers with urls
var pa= document.getElementById('image_set'); // reference the container element
pa=mr('evalBlock')
while(A.length){
pic=document.createElement('img');

n= Math.floor(Math.random()*A.length);
pic.src= A.splice(n, 1);
pa.appendChild(pic);
}
}[/CODE]
Copy linkTweet thisAlerts:
@cherb4authorNov 29.2009 — Many thanks - but should have said I'm a novice!

How do I call this from the page? What other code do I need to show the image?

Thanks
×

Success!

Help @cherb4 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...