PHP array to JS function ???

From: Date: Mon, 03 Mar 2003 14:53:09 +0000
Subject: PHP array to JS function ???
Groups: php.windows 
Request: Send a blank email to php-windows+get-18813@lists.php.net to get a copy of this message
Hi NG. I'm having some trouble parsing a php array to a javascript function. I've searched the web and found that others before me have had the same problem, but I haven't been able to find a solution to my problem yet. simple function example: "tal" is a php array and "count" is the size of that array. The array "tal" and the var "count" has of cause been assigned values prior to calling preload_images($tal, $count); ---------------------------------- <script language=javascript> function preload_images(tal, count) { var pics = new Array(count); for (i = 0; i < count; i++) { var pic = new Image(); pic.src = 'nef/graphic/ball_' + tal[i] + '.gif'; pics[i] = pic; document.write(pic.src + '<br>'); } } </script> ---------------------------------- The idea was just to pick up the images in the new array "pics" to make sure the images were preloaded. But I added the "document.write" statement to check the value of the image path. The result is as follows for sizeof($tal) = 14: ------------------------------- http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif http://localhost/nef/graphic/ball_undefined.gif -------------------------------- So my php array seems to have no values once in the javascript function. How can I fix this? Please help... /Aidal

« previous php.windows (#18813) next »