glennn.php Posted July 9, 2006 Share Posted July 9, 2006 i need to get an array into this javascipt, and i'm unable - can someone offer a hand? 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++; Quote Link to comment https://forums.phpfreaks.com/topic/14125-getting-a-php-array-into-javascript-help-needed/ Share on other sites More sharing options...
willfitch Posted July 10, 2006 Share Posted July 10, 2006 Hello Glenn (I think)0,Although the purpose of PHP is the capability of embedding with HTML (or JS in your case), I like to stick with concatinating the output within PHP variables. Doing this will fix your problem easily. Remember you can still embed the PHP with JS, but eventually I believe you will like this way better. One other point of assistance I can help you with is to use single quotes whenever possible. When your page is interpreted, double quotes are first read to check for embedded items, then read as a string. Single quotes are read as a literal, and you can just escape and concatenate your items within it like so:[code=php:0]<?php$name = 'Will';echo 'My name is '.$name.'. How are you?';?>[/code]Ok. Let's look at this:[code=php:0]<?php$isx=0;// Beginning of our JS content$js = '<script language="javascript" type="text/javascript">';// Create the "Text" variable array$js .= 'Text = new Array();';while ($idx <= 6) { $js .= 'Text['.$idx.']='.$textArray[$idx].';';}$js .= '</script>';?>[/code]This will help you build your JS array and allow you to access it via the "Text" variable. Is this the answer you are looking for?-- Will http://www.phpfever.com/ Quote Link to comment https://forums.phpfreaks.com/topic/14125-getting-a-php-array-into-javascript-help-needed/#findComment-55383 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.