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 7 of 7
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Random Image Generator

    Hi Everyone.

    I recently found this random image generator code. However it when the images show it displays them in their full size. Is it possible to edit this code in a way so that the image size will be the same everytime? So that all images will be shown as 100x50 for example.

    Thanks,
    Curt

    Code:
    <script language="Javascript">
    <!--
    // please keep these lines on when you copy the source
    // made by: Nicolas - http://www.javascript-page.com
    
    var currentdate = 0
    var core = 0
    
    function StringArray (n) {
      this.length = n;
      for (var i =1; i <= n; i++) {
        this[i] = ' '
    
      }
    }
    
    image = new StringArray(10)
    image[0] = '0.gif'
    image[1] = '1.gif'
    image[2] = '2.gif'
    image[3] = '3.gif'
    image[4] = '4.gif'
    image[5] = '5.gif'
    image[6] = '6.gif'
    image[7] = '7.gif'
    image[8] = '8.gif'
    image[9] = '9.gif'
    
    var ran = 60/image.length
    
    function ranimage() {
      currentdate = new Date()
      core = currentdate.getSeconds()
      core = Math.floor(core/ran)
        return(image[core])
    }
    
    document.write("<img src='" +ranimage()+ "'>")
    
    //-->
    </script>

  • #2
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Ive just noticed Ive put this in the wrong section. Sorry.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    It's fine, just don't cross post it will be moved accordingly.
    Code:
    <script type="text/javascript">
    <!--
    // please keep these lines on when you copy the source
    // made by: Nicolas - http://www.javascript-page.com
    
    var currentdate = 0
    var core = 0
    
    function StringArray (n) {
      this.length = n;
      for (var i =1; i <= n; i++) {
        this[i] = ' '
    
      }
    }
    
    image = new StringArray(10)
    image[0] = '0.gif'
    image[1] = '1.gif'
    image[2] = '2.gif'
    image[3] = '3.gif'
    image[4] = '4.gif'
    image[5] = '5.gif'
    image[6] = '6.gif'
    image[7] = '7.gif'
    image[8] = '8.gif'
    image[9] = '9.gif'
    
    var ran = 60/image.length
    
    function ranimage() {
      currentdate = new Date()
      core = currentdate.getSeconds()
      core = Math.floor(core/ran)
        return(image[core])
    }
    
    document.write("<img width="xx" height="xx" alt="" src='" +ranimage()+ "'>")
    
    //-->
    </script>
    It document.writes the image tag to the page, just add in the width and height that you desire there.

  • #4
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    hmm...it says there is an undetermined string error or something like that. SO it isn't working.

    I will keep trying.

    Thanks for your help.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    That is my fault sorry, I wasn't thinking at the time.
    Code:
    <script type="text/javascript">
    <!--
    // please keep these lines on when you copy the source
    // made by: Nicolas - http://www.javascript-page.com
    
    var currentdate = 0
    var core = 0
    
    function StringArray (n) {
      this.length = n;
      for (var i =1; i <= n; i++) {
        this[i] = ' '
    
      }
    }
    
    image = new StringArray(10)
    image[0] = '0.gif'
    image[1] = '1.gif'
    image[2] = '2.gif'
    image[3] = '3.gif'
    image[4] = '4.gif'
    image[5] = '5.gif'
    image[6] = '6.gif'
    image[7] = '7.gif'
    image[8] = '8.gif'
    image[9] = '9.gif'
    
    var ran = 60/image.length
    
    function ranimage() {
      currentdate = new Date()
      core = currentdate.getSeconds()
      core = Math.floor(core/ran)
        return(image[core])
    }
    
    document.write("<img width='xx' height='xx' alt='' src='" +ranimage()+ "'>")
    
    //-->
    </script>
    It should be single quotes not double quotes.

  • #6
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Its working now

    http://www.rallystuff.net/

    Thanks a lot,
    Curt

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    John do you care to elaborate? What syntax exactly are you referring to?


  •  

    Posting Permissions

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