View Full Version : Images Are Broken

10-08-2011, 11:28 PM
<script type="text/javascript">

var imageSrc = ['<img www.mysite.com/subfolder/001.jpg></img>','002.jpg','003.jpg',
var imageSrc2 = [];;

function copyRandom(){
if (0 == imageSrc2.length) {
imageSrc2 = imageSrc.concat();
var randNum = (Math.random()*imageSrc2.length) | 0;
return imageSrc2.splice(randNum, 1);

<!-- <button
onclick="document.getElementById('xx').innerHTML = (copyRandom());"> -->
onclick="document.getElementById('xx').innerHTML = (copyRandom());">
Draw A Card
<div id="xx"></div>
<!-- <div id="xx"></div> -->


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.

10-09-2011, 12:02 AM
Maybe ....
var imageSrc = ['<img src="www.mysite.com/subfolder/001.jpg"></img>'

10-09-2011, 12:10 AM
That's exactly what I was missing, thanks!

10-09-2011, 01:22 AM
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.


<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

<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.