ricktee76 Posted March 8, 2008 Share Posted March 8, 2008 I'm trying to echo a php array into the javascript, does anyone have any ideas as how it can be done? function showItemOfTheDay() { var xmlDocument = request.responseXML; var nodes = xmlDocument.selectNodes( '//item' ); var numberOfItems = nodes.length; var where = '[color=red][b]<?PHP echo "$msstrip"; ?>[/b][/color]'; var randomNumber = getRandomNumber( numberOfItems ); var selectedNode = nodes[randomNumber]; var thumbnail = selectedNode.selectSingleNode( 'media:thumbnail//@url' ); var title = selectedNode.selectSingleNode( 'title' ); // var link = selectedNode.selectSingleNode( 'link' ); divLink.innerHTML = '<img src="' + thumbnail.text + '" width="90" height="70" alt="' + title.text + '" border="0"/></a>'; // divLink.innerHTML = '<a href="' + link.text + '" target="_blank"><img src="' + thumbnail.text + '" width="90" height="60" alt="' + title.text + '" border="0"/></a>'; } // Eventhandler, will be fired for every state change on our XMLHttpRequest. function request_onReadyStateChange() { var status = request.readyState; divStatus.innerText = getStatusDescription( status ); if ( status == 4 ) { showItemOfTheDay(); } } function UpdateGadget() { var url = 'http://www.awebsite.com/things/are/here/page=[b][color=red]+ where +[/color][/b]'; request = new XMLHttpRequest(); request.onreadystatechange = request_onReadyStateChange; request.open("GET", url); request.send(); window.setTimeout(UpdateGadget, (1000 * 60 * 60 )); } // Eventhandler, will fire when the body of our gadget has completed loading. function Page_onLoad() { divStatus.style.display = "none"; UpdateGadget(); } </script> </head> <body onload="Page_onLoad();"> <g:background> <img id="imgNFLlogo" src="NFL-corner.png" /> <div id="divLink"></div> <div id="divStatus"></div> </g:background> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 8, 2008 Share Posted March 8, 2008 With an echo statement? The PHP should run before the JS if I'm not mistaken. So just echo it where you want it. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 use PHP to write the js code <?php $array = array('a', 'b', 'c'); $items = '"' . join ('","', $array) . '"'; echo "<script language='javascript'>\n"; echo "var jsarray = new Array ("; echo $items; echo ");\n"; echo "for (var i=0; i<3; i++) document.write(jsarray[i]);\n"; echo "</script>\n"; ?> Gives--> <script language='javascript'> var jsarray = new Array ("a","b","c"); for (var i=0; i<3; i++) document.write(jsarray[i]); </script> 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.