Click to See Complete Forum and Search --> : Ad rotator script


Saber_Ryan1
01-07-2004, 09:26 PM
I've gotten an ad rotator script from a website, but after filling in all the required lines with my URLs, I get an error when trying to view the page some times. Here's what the error says, "A Runtime Error has occurred. Do you wish to Debug? Line: 55 Error: Expected ';'". So there seems to be an error on line 55 - can someone figure out what it is, please?.. Here's the script for you all (with my URLs in it):

<SCRIPT>

// put info for randomly selected banners here, as in the examples

gfx0="http://rcm-images.amazon.com/images/G/01/associates/promotions/b1c-468x60.gif";

lnk0="http://www.amazon.com/exec/obidos/redirect?tag=mgsonline-20&creative=92489&camp=8117&link_code=dl1&path=subst/misc/amazon-cobrand-cc/v3/marketing-from-associates-step1.html/ref%3Db1_assoc_26";

alt0="Amazon.com Platinum Visa Card";

gfx1="http://www.mgsonline.net/home-banner-468x60.gif";

lnk1="http://www.amazon.com/exec/obidos/redirect-home/mgsonline-20";

alt1="In Association with Amazon.com";

gfx2="http://www.cafepress.com/cp/banners/cp_referral_468x60.gif";

lnk2="http://www.cafepress.com/cp/info/storeref.aspx?refby=mgsonline";

alt2="Design and Sell Merchandise Online for Free";

gfx3="http://www.alienware.com/affiliate_pages/banners/gaming_pc_banner_468x60.gif";

lnk3="http://www.alienware.com/index.aspx?from=_R__Y__A__N_:gaming_pc_banner_468x60";

alt3="Alienware - Gaming PC for PC Gaming";

len=4; // change to equal number of banners

today=new Date();

today=today.getTime()/10;

rnd=today%len;

document.writeln('<A HREF="'+eval("lnk"+rnd)+'"><IMG SRC="'+eval("gfx"+rnd)+'" ALT="'+eval("alt"+rnd)+'" WIDTH="468" HEIGHT="60"></A>');

</SCRIPT>

Line 55 is, by the way, the line that begins with, "document.writeln". Help would be greatly appreciated! :confused:

Thanks in advance,

David Harrison
01-08-2004, 03:33 AM
It could be that you have used more than one line for three of your variables, specifically gfx0, lnk0 &amp; lnk3. I'm pretty sure that you're only supposed to use one line for a variable but I'm not certain, I've never needed to use otherwise though.

Line 55 is where the error occured, however I do not know which of the lines is number 55 since numbering begins with the very first line of your document, not just the first line of the script.

Saber_Ryan1
01-08-2004, 08:34 AM
The line that begins with, "document.writeln", is line 55 of the HTML document. See any problems there? Thanks for the help, anyway..

requestcode
01-08-2004, 09:39 AM
I suggest you check these sites out for a better script:
http://www.javascriptkit.com/cutpastejava.shtml
http://www.dynamicdrive.com/

Saber_Ryan1
01-08-2004, 09:59 AM
Heh, I found the same script over again on javascriptkit.com. Here's the link: http://www.javascriptkit.com/script/cut149.shtml - you can see for yourself the error. This error occurs on line 144, however. If the page loads correctly, refresh it until you get the error. The page *will* load correctly sometimes, and sometimes it won't. Maybe it's one banner that isn't working correctly... Thanks for the links, anyway. I'll keep looking around.

jaegernaut
01-08-2004, 10:36 AM
Could be a mix up on all the double and single quotes.

Your line:
document.writeln('<A HREF="'+eval("lnk"+rnd)+'"><IMG SRC="'+eval("gfx"+rnd)+'" ALT="'+eval("alt"+rnd)+'" WIDTH="468" HEIGHT="60"></A>');

Retype as:
document.writeln("<A HREF="+eval('lnk'+rnd)+"><IMG SRC="+eval('gfx'+rnd)+" ALT="+eval('alt'+rnd)+" WIDTH='468' HEIGHT='60'></A>");

See if that helps.

Saber_Ryan1
01-08-2004, 11:02 AM
Hm.. I still get an error. It says that there's an expected ';' so maybe there's a missing ; somewhere.. I dunno. Anyway, I found a different script that does work.. the only downside to it is that it doesn't display any ALT for the images, meaning that it doesn't show any text when you scroll over them. I guess I could live without that, though.

Thanks allot for the help, everyone! :)

I don't know if anyone could or not, but if you can work the ALT (image description) into this new script, I'd really appreciate it. Here it is:
<script language="JavaScript">
<!--

/*
Random Image Link Script- By JavaScript Kit(http://www.javascriptkit.com)
Over 200+ free JavaScripts here!
Updated: 00/04/25
*/

function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="http://rcm-images.amazon.com/images/G/01/associates/promotions/b1c-468x60.gif"
myimages[2]="http://www.mgsonline.net/home-banner-468x60.gif"
myimages[3]="http://www.cafepress.com/cp/banners/cp_referral_468x60.gif"
myimages[4]="http://www.alienware.com/affiliate_pages/banners/gaming_pc_banner_468x60.gif"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.amazon.com/exec/obidos/redirect?tag=mgsonline-20&creative=92489&camp=8117&link_code=dl1&path=subst/misc/amazon-cobrand-cc/v3/marketing-from-associates-step1.html/ref%3Db1_assoc_26"
imagelinks[2]="http://www.amazon.com/exec/obidos/redirect-home/mgsonline-20"
imagelinks[3]="http://www.cafepress.com/cp/info/storeref.aspx?refby=mgsonline"
imagelinks[4]="http://www.alienware.com/index.aspx?from=_R__Y__A__N_:gaming_pc_banner_468x60"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
//-->
</script>

If nobody can do it, then I can just work with it like this, I guess.

Thanks again for all the help,

jaegernaut
01-08-2004, 11:26 AM
You could set up another array with the Alt text, and then just add the ALT= to the altarray[ry] like you are doing with the other arrays.

Something like this:

var myAlts = new Array()

myAlts[1]="Alt 1 Text"
myAlts[2]="Alt 2 text"
myAlts[3]="Alt 3 text"
myAlts[4]="Alt 4 text"

Then change your write line to something like this:

document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" alt="+myAlts[ry]+" title="+myAlts[ry]+" border=0></a>')

I added the title attribute because I think that Netscape uses title vs. alt.

Someone please correct me if I'm wrong on this.

David Harrison
01-08-2004, 11:27 AM
I went away and re-wrote the script, is this any good?

Saber_Ryan1
01-09-2004, 11:27 AM
Well, neither of them give me any errors, but Jaegernaut's idea, even though it desplays image description now, the description is always "+myAlts[ry]+" instead of what it is supposed to be. :confused: As for Lavalamp's, it doesn't get any errors either, but the image desplayed is nothing but the text "undefined"..

I did, however, manage to get a script that works perfectly, even with the image description. There is but one problem with it.. unlike any of the other scripts, this one puts a big ugly blue border around all of the banners. :mad: Any idea on how to get rid of it?? Thanks for all of the continued help, people! :) Here's the new script:

<SCRIPT>

// put info for randomly selected banners here, as in the examples
len=4;

gfx=new Array(len);
lnk=new Array(len);
alt=new Array(len);

gfx[0]="http://rcm-images.amazon.com/images/G/01/associates/promotions/b1c-468x60.gif";
lnk[0]="http://www.amazon.com/exec/obidos/redirect?tag=mgsonline-20&creative=92489&camp=8117&link_code=dl1&path=subst/misc/amazon-cobrand-cc/v3/marketing-from-associates-step1.html/ref%3Db1_assoc_26";
alt[0]="Amazon.com Platinum Visa Card";

gfx[1]="http://www.mgsonline.net/home-banner-468x60.gif";
lnk[1]="http://www.amazon.com/exec/obidos/redirect-home/mgsonline-20";
alt[1]="In Association with Amazon.com";

gfx[2]="http://www.cafepress.com/cp/banners/cp_referral_468x60.gif";
lnk[2]="http://www.cafepress.com/cp/info/storeref.aspx?refby=mgsonline";
alt[2]="Design and Sell Merchandise Online for Free";

gfx[3]="http://www.alienware.com/affiliate_pages/banners/gaming_pc_banner_468x60.gif";
lnk[3]="http://www.alienware.com/index.aspx?from=_R__Y__A__N_:gaming_pc_banner_468x60";
alt[3]="Alienware - Gaming PC for PC Gaming";



today=new Date();

today=today.getTime()/10;

rnd=Math.floor(today%len);

document.writeln('<A HREF="'+lnk[rnd]+'"><IMG SRC="'+gfx[rnd]+'" ALT="'+alt[rnd]+'" WIDTH="468" HEIGHT="60"></A>');
</SCRIPT>

When I put into an HTML document and view it, blue borders are always around the image.. :confused: I don't know if there IS any way to get rid of them, so if there isn't, I suppose I'll just have to live with 'em.

Thanks again!! :)

jaegernaut
01-09-2004, 11:33 AM
Add border=0 to your IMG tag.

document.writeln('<A HREF="'+lnk[rnd]+'"><IMG SRC="'+gfx[rnd]+'" ALT="'+alt[rnd]+'" WIDTH="468" HEIGHT="60" border="0"></A>');

That should remove that for you.

David Harrison
01-09-2004, 11:38 AM
Sorry about the undefined, I forgot to make sure that the random number was an interger. It works now.
Also, the border is due to the image being in a link, so to get rid of it, just set the border to 0. Anyway, I've uploaded the working script so you don't need to bother going through and correcting it.

Saber_Ryan1
01-09-2004, 11:51 AM
Okay - everything is working perfectly now! I'm satisfied. :) I browsed around on a couple of scripting forums and asked them my question, but this forum was the only one that I actually got any replies from! Thanks for everything! :)