Page 1 of 1

putting a php array into javascript

Posted: Sun Jul 09, 2006 4:26 pm
by glennn.php
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i am having trouble getting this array, "$text", distributed to this javascript - can anyone offer a hand...?

thanks
g

Code: Select all

global $onMouseOver, $onMouseOut, $picsArray, $textArray, $picUrl;						
		$idx = 0;
		while ($idx <= 6) {
			$pic  = $picsArray[$idx];
			$purl = $picUrl[$pic];

			$text  = $textArray[$idx];

			
		?> 
		<script language="JavaScript" type="text/javascript">

		  Text[8]=["<?php print "$text"; ?>","next line..."]
		  applyCssFilter()
                                 </script> 

<?
   	
//////

$line = "<td width=\"100\" background=\"stars/".$pic."\"><a href=\"".$phpLink."\" target=\"_blank\"><img src=\"stars/gold.gif\" width=\"100\" height=\"100\" border=\"0\" onMouseOver=\"stm(Text[8],Style[5])\" onMouseOut=\"htm()\" /></a></td>";
			}
			print $line."\n";
			$idx++;

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Jul 09, 2006 4:30 pm
by dull1554

Code: Select all

global $onMouseOver, $onMouseOut, $picsArray, $textArray, $picUrl;
$idx = 0;
while ($idx <= 6) {
$pic = $picsArray[$idx];
$purl = $picUrl[$pic];

$text = $textArray[$idx];


Print <<< EOT
<script language="JavaScript" type="text/javascript">

Text[8]=["{$text}","next line..."]
applyCssFilter()
</script>

EOT;

//////

$line = "<td width=\"100\" background=\"stars/".$pic."\"><a href=\"".$phpLink."\" target=\"_blank\"><img src=\"stars/gold.gif\" width=\"100\" height=\"100\" border=\"0\" onMouseOver=\"stm(Text[8],Style[5])\" onMouseOut=\"htm()\" /></a></td>";
}
print $line."\n";
$idx++;
might work.

Posted: Sun Jul 09, 2006 4:41 pm
by glennn.php
yes, i've tried something real similar - it's giving me the LAST value in the array on EACH instead of distributing them data out...

thanks - so close....

Posted: Sun Jul 09, 2006 4:47 pm
by feyd
If you disable bbcode in your posting, no syntax highlighting will happen... ;)