...

View Full Version : Banner rotation script.



nysmenu
07-23-2009, 12:31 AM
Guys, does anyone have a tut on making a banner rotation script. I would like to ad one to the site I am building. Thanks

nysmenu
07-23-2009, 01:47 AM
I 've been trying to work with this script but i can't get it to work. When I view in browser I get a blank page. does anyone have any suggestions? Thanks.


<SCRIPT language=JavaScript>

var img_width = "640";
var img_height = "360";
var img_title = "Click Here";

var links=new Array();
var pic=new Array();

//insert here your images src
pic[0]=<img src="images/IMGA0257.JPG" width="640" height="360" />;
pic[1]=<img src="images/IMGA0264.JPG" width="640" height="360" />;

//insert here your links
links[0]=

var xy=Math.floor(Math.random()*ad.length);//generates a random //digit and then makes it a whole number
document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+pic[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</SCRIPT>

Fou-Lu
07-23-2009, 01:49 AM
Moving from PHP to Javascript
Those pic[] values are not going to work, it likely just wants the 'images/IMGA02xx.jpg'. That is indicated in the document.write line (does document.write still work?) where it uses pic[xy].

nysmenu
07-23-2009, 01:58 AM
I don't follow you. Please explain. Thanks

nysmenu
07-24-2009, 01:24 AM
Anyone have any suggestions?

Old Pedant
07-24-2009, 01:51 AM
He means you should do this:


var pic = ["images/IMGA0257.JPG", "images/IMGA0264.JPG" ];

And then the rest of the code looks okay.

You would of course also need to do something similar with the links array. Maybe

var links = ["fish.html","mammals.html"];
Or wherever the images are supposed to link to.

randomuser773
07-24-2009, 01:56 AM
This is completely untested - I just fixed all the errors I could see immediately.
Report any relevant errors from the Firefox error console; there would have been some previously.
If you get no errors, put one of those images in an <img> tag and make sure it actually displays.


<script type='text/javascript'>

var img_width = 640;
var img_height = 360;
var img_title = "Click Here";

var links=new Array();
var pic=new Array();

//insert here your images src
pic[0]="images/IMGA0257.JPG";
pic[1]="images/IMGA0264.JPG";

links=["#","#"]; // Replace these with your links

var xy = Math.floor(Math.random()*pic.length);

document.write('<a href="'+links[xy]+'" target="_blank"><img src="'+pic[xy]+'" width="'+img_width+'" height="'+img_height+'" alt="'+img_title+'"></a>');
</script>

nysmenu
07-24-2009, 02:07 AM
This one seems to be working. How can I make rotate at random? Thanks

randomuser773
07-24-2009, 03:29 AM
This one seems to be working. How can I make rotate at random? ThanksThat one is or should be random, although with only two images it may be hard to appreciate.

What exactly do you mean by 'rotate at random'?

nysmenu
07-24-2009, 12:09 PM
Well, I didn't exactly mean for it to rotate out of order. Thank you. Is working.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum