Remove this Banner Ad

Any Javascript experts out there?

🥰 Love BigFooty? Join now for free.

I have been using a Java script but finding that is it grows it gets huge, and want to replace it with an array. Unfortunately that's a little over my head!

I'm currently doing the following :


var0="index000.gif"
lnk0="<a href='http://clubs.yahoo.com/clubs/timelordsfootyclub' target='resource window'>"
txt0="<font color='white'>Timelord's Footy Club</font></a>"

var1="index002.gif"
lnk1="<a href='http://www.fitzroyfc.com.au' target='resource window'>"
txt1="<font color='white'>Fitzroy FC (Vic)</font></a>"

now=new Date()
num=(now.getSeconds() )%1

if (num == 0)
{cliche=var0
link=lnk0
description=txt0}
if (num == 1)
{cliche=var1
link=lnk1
description=txt1}

document.write("<center><font color='white' size='-1'><i>Footypedia recommends :</i></font></center>")
document.write("<center>" + link + "<img src='" + cliche + "'>" + "</a></center>")
document.write("<center><font size='-3' color='white'>"+ link+description + "</font></center>")


But now its up to 31 items, the script has really blown out.

Wondering if there's a shorter way, using arrays?

Anyone?
 
Used to use arrays in Fortran and Basic umpteen years ago but can't remember anything about them now.
 
Originally posted by Fred
Used to use arrays in Fortran and Basic umpteen years ago but can't remember anything about them now.

The general idea of arrays is fine by me, I still use them in QBasic to this day. Its just using them in javascript that has me knackered!
 
Tried a Google search?
 

Log in to remove this Banner Ad

What you have here is a situation where a client-side solution has gotten too large and should now be replaced by a server-side solution.

That is, you should have some code that picks up the required link and outputs it to the client (browser) rather than sending everything to the browser and have it chug through the options.

Search Google for link rotation scripts.
 
Originally posted by Mobbenfuhrer
I have been using a Java script but finding that is it grows it gets huge, and want to replace it with an array. Unfortunately that's a little over my head!

I'm currently doing the following :


var0="index000.gif"
lnk0="<a href='http://clubs.yahoo.com/clubs/timelordsfootyclub' target='resource window'>"
txt0="<font color='white'>Timelord's Footy Club</font></a>"

var1="index002.gif"
lnk1="<a href='http://www.fitzroyfc.com.au' target='resource window'>"
txt1="<font color='white'>Fitzroy FC (Vic)</font></a>"

now=new Date()
num=(now.getSeconds() )%1

if (num == 0)
{cliche=var0
link=lnk0
description=txt0}
if (num == 1)
{cliche=var1
link=lnk1
description=txt1}

document.write("<center><font color='white' size='-1'><i>Footypedia recommends :</i></font></center>")
document.write("<center>" + link + "<img src='" + cliche + "'>" + "</a></center>")
document.write("<center><font size='-3' color='white'>"+ link+description + "</font></center>")


But now its up to 31 items, the script has really blown out.

Wondering if there's a shorter way, using arrays?

Anyone?
You would be better off doing a search through the Lycos area and you will get a really good amount of java in that. Good luck with it.
 
if (num == 0)
{cliche=var0
link=lnk0
description=txt0}
if (num == 1)
{cliche=var1
link=lnk1
description=txt1}

Now I'm not big on the syntax, but it looks like you need to put your "num" variable to better use.

for example:

make your arrays:
var = new Array();
lnk = new Array();
txt = new Array();

Your arrays:
var[0] ="blah blah blah"
var[1] = "etc"
lnk[0] = "etc etc

find your arrays, using random numbers
cliche==var[num]
link==lnk[num]
description==txt[num]

Not at all sure on the above syntax, but do you get the idea ?

A different example:

function random_content(){
var mycontent=new Array()
//specify random content below.
mycontent[1]='<b>Random content 1</b>'
mycontent[2]='<b>Random content 2</b>'
mycontent[3]='<b>Random content 3</b>'
mycontent[4]='<b>Random content 4</b>'
mycontent[5]='<b>Random content 5</b>'


var ry=Math.floor(Math.random()*mycontent.length)
if (ry==0)
ry=1
document.write(mycontent[ry])
}
random_content()

I hope this helps.
 

Remove this Banner Ad

Any Javascript experts out there?

🥰 Love BigFooty? Join now for free.

Back
Top