Jump to content

Echo PHP in javascript


ricktee76

Recommended Posts

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.