neridaj Posted April 10, 2008 Share Posted April 10, 2008 Hello, I have a multidim array that is generated with php and I don't understand why/how to fix these errors: Error: atrarr[0] has no properties Error: atrarr[imgname] has no properties I put an alert in the change_slide() function and it says the var imgname is undefined however, upon viewing the php output the var imgname is defined. Here is the php output: <!-- start hiding var atrarr = new Array(); atrarr[0][0] ="01.jpg"; atrarr[0][1] =1600; atrarr[0][2] =1063; atrarr[1][0] ="02.jpg"; atrarr[1][1] =1600; atrarr[1][2] =1063; atrarr[2][0] ="03.jpg"; atrarr[2][1] =1600; atrarr[2][2] =1063; atrarr[3][0] ="04.jpg"; atrarr[3][1] =1600; atrarr[3][2] =1063; atrarr[4][0] ="05.jpg"; atrarr[4][1] =1600; atrarr[4][2] =1063; atrarr[5][0] ="06.jpg"; atrarr[5][1] =1600; atrarr[5][2] =1063; atrarr[6][0] ="07.jpg"; atrarr[6][1] =1600; atrarr[6][2] =1063; atrarr[7][0] ="08.jpg"; atrarr[7][1] =1600; atrarr[7][2] =1063; atrarr[8][0] ="09.jpg"; atrarr[8][1] =1600; atrarr[8][2] =1063; atrarr[9][0] ="10.jpg"; atrarr[9][1] =1600; atrarr[9][2] =1063; atrarr[10][0] ="11.jpg"; atrarr[10][1] =1600; atrarr[10][2] =1063; atrarr[11][0] ="12.jpg"; atrarr[11][1] =1600; atrarr[11][2] =1063; atrarr[12][0] ="13.jpg"; atrarr[12][1] =1600; atrarr[12][2] =1063; atrarr[13][0] ="14.jpg"; atrarr[13][1] =1600; atrarr[13][2] =1063; atrarr[14][0] ="15.jpg"; atrarr[14][1] =1600; atrarr[14][2] =1063; atrarr[15][0] ="16.jpg"; atrarr[15][1] =1600; atrarr[15][2] =1063; atrarr[16][0] ="17.jpg"; atrarr[16][1] =1600; atrarr[16][2] =1063; atrarr[17][0] ="18.jpg"; atrarr[17][1] =1600; atrarr[17][2] =1063; atrarr[18][0] ="19.jpg"; atrarr[18][1] =1600; atrarr[18][2] =1063; atrarr[19][0] ="20.jpg"; atrarr[19][1] =1600; atrarr[19][2] =1063; atrarr[20][0] ="21.jpg"; atrarr[20][1] =1600; atrarr[20][2] =1063; atrarr[21][0] ="22.jpg"; atrarr[21][1] =1600; atrarr[21][2] =1063; atrarr[22][0] ="23.jpg"; atrarr[22][1] =1600; atrarr[22][2] =1063; atrarr[23][0] ="24.jpg"; atrarr[23][1] =1063; atrarr[23][2] =1600; atrarr[24][0] ="25.jpg"; atrarr[24][1] =1063; atrarr[24][2] =1600; atrarr[25][0] ="26.jpg"; atrarr[25][1] =1600; atrarr[25][2] =1063; atrarr[26][0] ="27.jpg"; atrarr[26][1] =1063; atrarr[26][2] =1600; atrarr[27][0] ="28.jpg"; atrarr[27][1] =1063; atrarr[27][2] =1600; atrarr[28][0] ="29.jpg"; atrarr[28][1] =1600; atrarr[28][2] =1063; atrarr[29][0] ="30.jpg"; atrarr[29][1] =1600; atrarr[29][2] =1063; atrarr[30][0] ="31.jpg"; atrarr[30][1] =1600; atrarr[30][2] =1063; atrarr[31][0] ="32.jpg"; atrarr[31][1] =1600; atrarr[31][2] =1063; var imgnum = 09; var imgname = "09.jpg"; var imgct = pictarr.length - 1; function change_slide(direction) { alert(imgname); if(document.images) { imgnum = imgnum + direction; if(imgnum < imgct || imgnum > 0) { document.getElementById("arrowprev").style.visibility = "visible" document.getElementById("arrownext").style.visibility = "visible" } if(imgnum == imgct) { document.getElementById("arrownext").style.visibility = "hidden" } if(imgnum == 0) { document.getElementById("arrowprev").style.visibility = "hidden" } } document.getElementById("slideshow").setAttribute("src", "members/test25/8337/" + atrarr[imgname][0]) document.getElementById("caption").innerHTML = atrarr[imgname] } // end hiding --> Here is the php code: <?php $pictarr = get_imgarr(); $atrarr = get_imgdim(); $imgfolder = get_imgdir(); $trimgnum = trim($_GET['in'], ".jpg"); ?> <script type="text/javascript" charset="utf-8"> <!-- start hiding <?php echo 'var atrarr = new Array();' . "\n"; // define array in JavaScript $count = count($pictarr); for($i = 0; $i < $count; $i++) { echo 'atrarr['. $i .']['. 0 .'] ="'. $pictarr[$i] .'";'."\n"; echo 'atrarr['. $i .']['. 1 .'] ='. $atrarr[$pictarr[$i]]["width"] .';'."\n"; echo 'atrarr['. $i .']['. 2 .'] ='. $atrarr[$pictarr[$i]]["height"] .';'."\n"; } ?> var imgnum = <?php echo $trimgnum; ?>; var imgname = "<?php echo $trimgnum .'.jpg'; ?>"; var imgct = pictarr.length - 1; function change_slide(direction) { alert(imgname); if(document.images) { imgnum = imgnum + direction; if(imgnum < imgct || imgnum > 0) { document.getElementById("arrowprev").style.visibility = "visible" document.getElementById("arrownext").style.visibility = "visible" } if(imgnum == imgct) { document.getElementById("arrownext").style.visibility = "hidden" } if(imgnum == 0) { document.getElementById("arrowprev").style.visibility = "hidden" } } document.getElementById("slideshow").setAttribute("src", "<?php echo $imgfolder; ?>" + atrarr[imgname][0]) document.getElementById("caption").innerHTML = atrarr[imgname] } // end hiding --> </script> Quote Link to comment Share on other sites More sharing options...
haku Posted April 10, 2008 Share Posted April 10, 2008 Where are you getting the error? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.