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 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2009
    Location
    www.nn11.darkbb.com
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Random image script

    Does anyone have a script, that can display a random image of the images I select?I'm going to use it for a type of captcha. I think this would be easier in javascript, so yes I am in the right section.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question More information please ...

    Quote Originally Posted by tonynoname123 View Post
    Does anyone have a script, that can display a random image of the images I select?I'm going to use it for a type of captcha. I think this would be easier in javascript, so yes I am in the right section.
    Clarification please ...

    Where are the images coming from?
    How are you getting the "images I select?"
    Does the random display occur only once when page is loaded?
    Do you have any sample starting code to show position, layouot, etc.?

  • #3
    New Coder
    Join Date
    Nov 2009
    Location
    www.nn11.darkbb.com
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sorry, I want the images from a url, I just paste the url into the source code as src="URL" yes only once per load, no, I don't have any sample codes...they're from my forum.
    Last edited by tonynoname123; 12-19-2009 at 04:57 AM. Reason: none

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    This should meet your needs:-

    Code:
    <img  id = "captchaImage" width = "150" height = "150" >
    
    <script type = "text/javascript">
    
    var imgArray = ['One.gif','Two.gif','Three.gif','Four.gif','Five.gif', 'Six.gif', 'Seven.gif', 'Eight.gif', 'Nine.gif'];
    function randOrd(){return (Math.round(Math.random())-0.5)}
    imgArray.sort(randOrd);
    alert (imgArray);  // FOR TESTING
    var len = imgArray.length;
    var count = 0;
    
    function rotate() {
    document.getElementById("captchaImage").src = imgArray[count];
    count++;
    if (count>=len) {count = 0}
    var tcaptchaImage = window.setTimeout("rotate()", 5000);  // 5 seconds
    }
    
    rotate();
    
    </script>
    If you want to use URLs for the images, simply make your imageArray a list of the relevent URLs. If one image only is to be shown at page load then obviously the rotate() function is redundant. All you need is
    document.getElementById("captchaImage").src = imgArray[0];


    Quizmaster: What is the meaning of the French expression "coup de grâce"?
    Contestant: Lawnmower.
    Last edited by Philip M; 12-19-2009 at 08:35 AM.

  • Users who have thanked Philip M for this post:

    tonynoname123 (12-20-2009)

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Smile If you snooze, you lose ...

    Well, it looks like 'Philip M' codes in the UK while I'm sleeping in the US
    but his suggestion is pretty close to what I would have done.

  • #6
    New Coder
    Join Date
    Nov 2009
    Location
    www.nn11.darkbb.com
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Perfect! Thanks! You can see a demo of what I used it for at www.1836.tk
    Last edited by tonynoname123; 12-20-2009 at 04:37 AM.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    I would suggest that you make your images rather larger and more legible for the benefit of users with less-than-perfect sight.

  • #8
    New Coder
    Join Date
    Nov 2009
    Location
    www.nn11.darkbb.com
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ok, I'll do that.


  •  

    Tags for this Thread

    Posting Permissions

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