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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    Washington State
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question DORAND - Do random when function called...

    Isn't there an easy command called something like DORAND? I am trying to get a script to display a random image and I can't work with all the other random image scripts. Heres kind of what I am looking for:


    function randIMG(){
    DORAND:

    rand1 = "image1.src='images/box_time.gif'"
    rand2 = "image2.src='images/box_time.gif'"
    rand3 = "image3.src='images/box_time.gif'"
    rand4 = "image4.src='images/box_time.gif'"

    ENDDORAND:
    }


    Something like that. Any comments or suggestions would greatly be apreciated. Thanks.
    ~ Isaac Lloyd ~
    Website Design & Development
    http://www.IsaacLloyd.com

  • #2
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Here is js code...

    Code:
    <script language="JavaScript">
    
    function randomImage(){
    var numofimages=5;
    var randomnum = Math.floor(Math.random() * numofimages);
    document.getElementById("myimg").src="images/image"+randomnum+".jpg";
    }
    window.onLoad=randomImage();
    </script>
    Add the following code to your body tag where u need the image.

    Code:
    <img src="images/image1.jpg" id="myimg">
    Be sure to provide images with image1.jpg, image2.jpg......etc...

    Have fun.

    Afru.

  • #3
    New Coder
    Join Date
    Dec 2002
    Location
    Washington State
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you said: var numofimages=5; now when javascript does the math, will that include the number 0?

    Thanks,

    ~Isaac Lloyd~
    ~ Isaac Lloyd ~
    Website Design & Development
    http://www.IsaacLloyd.com


  •  

    Posting Permissions

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