putting a php array into javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

putting a php array into javascript

Post 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]
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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.
glennn.php
Forum Commoner
Posts: 41
Joined: Sat Jul 08, 2006 12:26 pm

Post 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....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you disable bbcode in your posting, no syntax highlighting will happen... ;)
Post Reply