My problem is that it doesn't work every time. I have tested it in IE8, Chrome, and Firefox 3. I have noticed that when it doesn't work IE says "there are errors on this page" (bottom left hand corner), witht he details of:
Message: Object expected Line: 247 Char: 1 Code: 0 URI: http://www.shazbots.org/
here is the code for the page, it grabs 10 images from a database and preloads them
<script language="javascript" type="text/javascript">
images = new Array();
images_backup = new Array();
links = new Array();
function preloader()
{
// counter
var i = 0;
// create object
imageObj = new Image();
// set image list
<?php
$conn=mysql_connect("localhost","user","pass");
mysql_select_db("db", $conn);
$sql = "SELECT * FROM `images1`";
$sql=mysql_query($sql,$conn) or die(mysql_error());
while ($newArray=mysql_fetch_array($sql))
{
$img[$a]=$newArray['small_src'];
$link[$a]="images_big.php?auto=".$newArray['auto'];
$cap[$a]=$newArray['cap'];
$a++;
}
//picks random numbers
$random[0]=rand(0,$a);
$random[1]=rand(0,$a);
$random[2]=rand(0,$a);
$random[3]=rand(0,$a);
$random[4]=rand(0,$a);
$random[5]=rand(0,$a);
$random[6]=rand(0,$a);
$random[7]=rand(0,$a);
$random[8]=rand(0,$a);
$random[9]=rand(0,$a);
//check to make sure that all the images are valid, if it isn't, grab a new one
while ($img[$random[0]] == ""){$random[0]=rand(0,$a);}
while ($img[$random[1]] == ""){$random[1]=rand(0,$a);}
while ($img[$random[2]] == ""){$random[2]=rand(0,$a);}
while ($img[$random[3]] == ""){$random[3]=rand(0,$a);}
while ($img[$random[4]] == ""){$random[4]=rand(0,$a);}
while ($img[$random[5]] == ""){$random[5]=rand(0,$a);}
while ($img[$random[6]] == ""){$random[6]=rand(0,$a);}
while ($img[$random[7]] == ""){$random[7]=rand(0,$a);}
while ($img[$random[8]] == ""){$random[8]=rand(0,$a);}
while ($img[$random[9]] == ""){$random[9]=rand(0,$a);}
?>
/*sets the javascript variables equal to the php variables*/
images[0]="<?php echo $img[$random[0]]; ?>";
images[1]="<?php echo $img[$random[1]]; ?>";
images[2]="<?php echo $img[$random[2]]; ?>";
images[3]="<?php echo $img[$random[3]]; ?>";
images[4]="<?php echo $img[$random[4]]; ?>";
images[5]="<?php echo $img[$random[5]]; ?>";
images[6]="<?php echo $img[$random[6]]; ?>";
images[7]="<?php echo $img[$random[7]]; ?>";
images[8]="<?php echo $img[$random[8]]; ?>";
images[9]="<?php echo $img[$random[9]]; ?>";
links[0]="<?php echo $link[$random[0]]; ?>";
links[1]="<?php echo $link[$random[1]]; ?>";
links[2]="<?php echo $link[$random[2]]; ?>";
links[3]="<?php echo $link[$random[3]]; ?>";
links[4]="<?php echo $link[$random[4]]; ?>";
links[5]="<?php echo $link[$random[5]]; ?>";
links[6]="<?php echo $link[$random[6]]; ?>";
links[7]="<?php echo $link[$random[7]]; ?>";
links[8]="<?php echo $link[$random[8]]; ?>";
links[9]="<?php echo $link[$random[9]]; ?>";
// start preloading
for(i=0; i<=9; i++)
{
imageObj.src=images[i];
}
document.getElementById("img1").src = images[0];
document.getElementById("img2").src = images[1];
document.getElementById("img3").src = images[2];
document.getElementById("img4").src = images[3];
document.getElementById("img5").src = images[4];
document.getElementById("img6").src = images[5];
document.getElementById("img7").src = images[6];
document.getElementById("link1").href = links[0];
document.getElementById("link2").href = links[1];
document.getElementById("link3").href = links[2];
document.getElementById("link4").href = links[3];
document.getElementById("link5").href = links[4];
document.getElementById("link6").href = links[5];
document.getElementById("link7").href = links[6];
}
function ScrollRight()
{
//moves the images to the right
document.getElementById("img1").src = images[9];
document.getElementById("img2").src = images[0];
document.getElementById("img3").src = images[1];
document.getElementById("img4").src = images[2];
document.getElementById("img5").src = images[3];
document.getElementById("img6").src = images[4];
document.getElementById("img7").src = images[5];
document.getElementById("link1").href = links[9];
document.getElementById("link2").href = links[0];
document.getElementById("link3").href = links[1];
document.getElementById("link4").href = links[2];
document.getElementById("link5").href = links[3];
document.getElementById("link6").href = links[4];
document.getElementById("link7").href = links[5];
images[10]=images[0];
images[11]=images[1];
images[12]=images[2];
images[13]=images[3];
images[14]=images[4];
images[15]=images[5];
images[16]=images[6];
images[17]=images[7];
images[18]=images[8];
images[19]=images[9];
images[0]=images[19];
images[1]=images[10];
images[2]=images[11];
images[3]=images[12];
images[4]=images[13];
images[5]=images[14];
images[6]=images[15];
images[7]=images[16];
images[8]=images[17];
images[9]=images[18];
links[10]=links[0];
links[11]=links[1];
links[12]=links[2];
links[13]=links[3];
links[14]=links[4];
links[15]=links[5];
links[16]=links[6];
links[17]=links[7];
links[18]=links[8];
links[19]=links[9];
links[0]=links[19];
links[1]=links[10];
links[2]=links[11];
links[3]=links[12];
links[4]=links[13];
links[5]=links[14];
links[6]=links[15];
links[7]=links[16];
links[8]=links[17];
links[9]=links[18];
}
function ScrollLeft()
{
//moves images to the left
images[0]=images[1];
images[1]=images[2];
images[2]=images[3];
images[3]=images[4];
images[4]=images[5];
images[5]=images[6];
images[6]=images[7];
images[7]=images[8];
images[8]=images[9];
images[9]=images[0];
links[0]=links[1];
links[1]=links[2];
links[2]=links[3];
links[3]=links[4];
links[4]=links[5];
links[5]=links[6];
links[6]=links[7];
links[7]=links[8];
links[8]=links[9]; /*THIS IS LINE 247*/
links[9]=links[0];
document.getElementById("img1").src = images[0];
document.getElementById("img2").src = images[1];
document.getElementById("img3").src = images[2];
document.getElementById("img4").src = images[3];
document.getElementById("img5").src = images[4];
document.getElementById("img6").src = images[5];
document.getElementById("img7").src = images[6];
document.getElementById("link1").href = links[0];
document.getElementById("link2").href = links[1];
document.getElementById("link3").href = links[2];
document.getElementById("link4").href = links[3];
document.getElementById("link5").href = links[4];
document.getElementById("link6").href = links[5];
document.getElementById("link7").href = links[6];
}
</script>
and here is how I call it:
<body onload="preloader()"> <!--all my other code--> <img src="site_image/previous_images.jpg" width="30" name="previous" height="84" alt="Previous Image" onclick="ScrollLeft()"/> <a id="link1" href="<?php echo $link[$random[0]]; ?>"> <img id="img1" src="<?php echo $img[$random[0]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link2" href="<?php echo $link[$random[1]]; ?>"> <img id="img2" src="<?php echo $img[$random[1]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link3" href="<?php echo $link[$random[2]]; ?>"> <img id="img3" src="<?php echo $img[$random[2]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link4" href="<?php echo $link[$random[3]]; ?>"> <img id="img4" src="<?php echo $img[$random[3]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link5" href="<?php echo $link[$random[4]]; ?>"> <img id="img5" src="<?php echo $img[$random[4]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link6" href="<?php echo $link[$random[5]]; ?>"> <img id="img6" src="<?php echo $img[$random[5]]; ?>" alt="" width="95px" height="82" border="0"/></a> <a id="link7" href="<?php echo $link[$random[6]]; ?>"> <img id="img7" src="<?php echo $img[$random[6]]; ?>" alt="" width="95px" height="82" border="0"/></a> <img src="http://www.shazbots.org/site_image/next_images.jpg" name="next" alt="image rollover" onclick="ScrollRight()" height="84" width="30"/> </body>
You can see this in use at www.shazbots.org it's displayed at the bottom of the page.
I'm just wondering if anyone sees anything that they think is wrong that could cause it to not work every time.
Thanks for any help.

New Topic/Question
Reply



MultiQuote




|