Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Banner rotation script.

    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

  • #2
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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>

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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].
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't follow you. Please explain. Thanks

  • #5
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone have any suggestions?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    He means you should do this:
    Code:
    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
    Code:
    var links = ["fish.html","mammals.html"];
    Or wherever the images are supposed to link to.

  • #7
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    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.

    Code:
    <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>

  • #8
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This one seems to be working. How can I make rotate at random? Thanks

  • #9
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by nysmenu View Post
    This one seems to be working. How can I make rotate at random? Thanks
    That 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'?

  • #10
    Regular Coder
    Join Date
    Jul 2009
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I didn't exactly mean for it to rotate out of order. Thank you. Is working.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •