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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Images Are Broken

    Code:
    <body>
    <center>
    <script type="text/javascript">
    
    var imageSrc = ['<img www.mysite.com/subfolder/001.jpg></img>','002.jpg','003.jpg',
    '004.jpg','005.jpg','006.jpg'];
    var imageSrc2 = [];;
    
    function copyRandom(){
    if (0 == imageSrc2.length) {
    imageSrc2 = imageSrc.concat();
    }
    var randNum = (Math.random()*imageSrc2.length) | 0;
    return imageSrc2.splice(randNum, 1);
    }
    </script>
    
    <!-- <button
    onclick="document.getElementById('xx').innerHTML = (copyRandom());"> -->
    <button
    onclick="document.getElementById('xx').innerHTML = (copyRandom());">
    Draw A Card
    </button>
    <div id="xx"></div>
    <!-- <div id="xx"></div> -->
    
    </center>
    </body>
    Why are my images broken in this script? Specifically "<img www.mysite.com/subfolder/001.jpg></img>" as the rest are just placeholders until I solve the first one.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Maybe ....
    var imageSrc = ['<img src="www.mysite.com/subfolder/001.jpg"></img>'

  • Users who have thanked DaveyErwin for this post:

    Tgawe (10-08-2011)

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's exactly what I was missing, thanks!

  • #4
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hopefully this is an okay double-post considering it's a new question. (Maybe I should just make a new thread?)

    How would I go about writing how many images are left in the pool to display before it resets? I've tried doing document.write's and such but it either doesn't update or doesn't count properly at all. I honestly have no idea what I'm doing in regards to this, but this is the only time I need to do anything with Javascript and HTML so any help is appreciated.

    EDIT:

    Code:
    <div id="xx"></div>
    <button style="height: 50px; width: 200px";
    onclick="document.getElementById('xx').innerHTML = (copyRandom()); document.getElementById('example').innerHTML = 'Cards Remaining: ' + imageSrc.length;">
    Draw A Card
    </button>
    
    
    <div style="color: #FFFFFF;" id="example">Cards Remaining: null</div>
    I managed to get this code so it updates both the image and changes 'example' to whatever imageSrc.length is. The problem now is that imageSrc.length is always 20. How do I get the number of images it hasn't chosen yet? (Or how many it has chosen so far. Either works for me.)

    EDIT2: Solved! imageSrc needed to be imageSrc2. Woops.
    Last edited by Tgawe; 10-09-2011 at 01:30 AM.


  •  

    Posting Permissions

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