Javascript problem- Random Image Generator

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Get Involved
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
Oliveman
Registered User
Posts: 6
Joined: Wed Jul 30, 2008 8:43 pm

Javascript problem- Random Image Generator

Post by Oliveman »

I'm using the following code to randomize an image when the page loads.. but it's not working so hot.

Code: Select all

<!--
var currentdate = 0
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '

}
}

image = new StringArray(8)
image[0] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem1.gif'
image[1] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem2.gif'
image[2] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem3.gif'
image[3] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem4.gif'
image[4] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem5.gif'
image[5] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem6.gif'
image[6] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem7.gif'
image[7] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem8.gif'

var ran = 60/image.length

function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}
window.document.image.navMem.src = '" +ranimage()+ "'

//-->
Just had a thought- should I put the last bit in a function and run it using the body tag's onLoad event? What is wrong with my code?
User avatar
Sherry222
Registered User
Posts: 68
Joined: Tue Jun 08, 2010 3:14 am
Location: Igloos for sale... bearly used

Re: Javascript problem- Random Image Generator

Post by Sherry222 »

Part of it might be that you need to use the whole link path to your images.

Code: Select all

image[0] = '/gaforum/styles/GuildWarsAlliance/imageset/navMem1.gif'

Code: Select all

image[0] = 'http://www.yourdomain.something/directoryname/images/navMem1.gif'
There's a fever in the funkhouse now...
Oliveman
Registered User
Posts: 6
Joined: Wed Jul 30, 2008 8:43 pm

Re: Javascript problem- Random Image Generator

Post by Oliveman »

haha this came out of the blue! Thanks for the reply 2 years later : ) had completely forgotten about my post
User avatar
Sherry222
Registered User
Posts: 68
Joined: Tue Jun 08, 2010 3:14 am
Location: Igloos for sale... bearly used

Re: Javascript problem- Random Image Generator

Post by Sherry222 »

:) Yeah... better late than never. The only reason I answered it was because I've been working on placing a random image generator in my forum recently and one of the problems to solve was why were the images not showing. Turned out it was because they required the whole link.

So anyways, I saw your post while I was looking for something else and thought I'd post. Thx for your reply and take care. And actually... it's 4 years later ;)
There's a fever in the funkhouse now...
Locked

Return to “[3.0.x] Support Forum”