It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Display Multiple Random Images Side by Side

Display Multiple Random Images Side by Side

Postby j_koi on Tue May 20, 2008 7:06 pm

Please help.

I need to display 5 random images side by side on a web page. I have total of 10 images for the random 5 images.

The 10 images are:
0.jpg
1.jpg
2.jpg
3.jpg
:
:
9.jpg

I have tried to use two functions to do the job, but I don't know how to call the last function, please give me some hints, thank you .

The javascript I have tried is:

/* this function randomInteger () generates random numbers*/

function randomInteger(size) {
return Math.floor((size+1)* Math.random());
}


/* this function showImg() displays random images*/

function showImg( ) {
var imgNumber= randomInteger(9);
return imgNumber ;
document.write( " <img src= ' " + imgNumber+ " .jpg ' / > ");
}

// How can I call the function showImg ? I do not have any values passing into its parameter.
// Am I on the right track?
// Thank you for any helps.
j_koi
 
Posts: 0
Joined: Tue May 20, 2008 6:09 pm

Postby leonard on Wed May 21, 2008 11:17 am

Am I on the right track?


Basically I suggest not to use document.write.

If I'd write this randomizing function I would have a DIV-Tag in the HTML-code and a JavaScript function which puts the configurable amounts of images into the DIV-Tag, using its ID.

If I have time I'll post an example.

cheers!
- leonard
:%s/^M//
There are 10 kinds of people:
Those who understand binary and those who don't.
User avatar
leonard
100+ Club
 
Posts: 147
Joined: Tue Dec 18, 2007 7:11 am
Location: Switzerland

Postby rangana on Thu May 22, 2008 1:41 am

I've got a random image script, but is confuse with your requirements. Could you rephrase it.

What I understand is you have 5 section for images. So this 5 section should randomly display images..or something else?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests