/    Sign up×
Community /Pin to ProfileBookmark

Using random image script more than 2 times on same page

Hi all… I’m here as many users to learn and share (more learn as you will see :rolleyes: )

This time I’m trying to use a random image script that looks like this between <head> – </head>

[quote]

<!– Start random images –>
<script language=”JavaScript”>
// Cargando las imagenes que se necesiten.
var foto = new Array() // no cambiar esto

foto[0] = ‘spidera-aa.jpg’
foto[1] = ‘spidera-ab.jpg’
foto[2] = ‘spidera-ac.jpg’
foto[3] = ‘spidera-ad.jpg’
foto[4] = ‘spidera-ae.jpg’

var j = 0
var p = foto.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = foto[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function muestrafoto(){
document.write(‘<img src=”‘+foto[whichImage]+'”>’);
}

//–>
</script>
<!– Ends random javascript –>

[/quote]

And this on the table

[quote]


<td><script language=”JavaScript”>
showImage();
</script> a</td>

[/quote]

It works just fine but in order of using random images in more than one cell in my page I copied the entire script between head to head and replace the “theimages”, “showimages”, and images name which works fine, but the entire page will have 4 to 6 spots with random images which will be an endless piece of code

My question is how can I modify or what should I modify in order to call the same random code with several spots… I did this but is not working…

[quote]


<!– Start random images javascript –>
<script language=”JavaScript”>
// Loading images.
var theImages = new Array() // stay fixed
var foto = new Array() // stay fixed

theImages[0] = ‘spider-01.jpg’
theImages[1] = ‘spider-02.jpg’
theImages[2] = ‘spider-03.jpg’
theImages[3] = ‘spider-04.jpg’
theImages[4] = ‘spider-05.jpg’
foto[0] = ‘spidera-aa.jpg’
foto[1] = ‘spidera-ab.jpg’
foto[2] = ‘spidera-ac.jpg’
foto[3] = ‘spidera-ad.jpg’
foto[4] = ‘spidera-ae.jpg’

var j = 0
var p = theImages.length;
var q = foto.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
for (i = 0; i < q; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
preBuffer[i].src = foto[i]
}

var whichImage = Math.round(Math.random()*(p-1));
var whichImage = Math.round(Math.random()*
(p-1));
function showImage(){
document.write(‘<img src=”‘+theImages[whichImage]+'”>’);
document.write(‘<img src=”‘+foto[whichImage]+'”>’);
}

//–>
</script>
<!– Finish random images javascript –>

[/quote]

What should I change in order of adding more than one random in the same page using the same code?

Yes I’m new on javascript 😮 but I’m trying…. I’m trying… 😮

Any help is well appreciated

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@blonicauthorApr 27.2007 — Please forget about this post, after few hours and lots of changes is working. ?

Thanks ?
×

Success!

Help @blonic 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...