Jump to content

Javascript working with PHP


Sware

Recommended Posts

Bascially I have a Javascript script that has to have PHP elements in it. When I try to echo it all it doesn't work, and when I put PHP in the variable it still doesnt work.. Any luck?

 

This is what I currently have..

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='$rssticker->recent-post->subject'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

I tried it this way also.

pausecontent[0]='<?php $rssticker->recent-post->subject ?>';

 

No worky. Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/
Share on other sites

Bascially I have a Javascript script that has to have PHP elements in it. When I try to echo it all it doesn't work, and when I put PHP in the variable it still doesnt work.. Any luck?

 

This is what I currently have..

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='$rssticker->recent-post->subject'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

I tried it this way also.

pausecontent[0]='<?php $rssticker->recent-post->subject ?>';

 

No worky. Any suggestions?

 

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='". $rssticker->recent-post->subject . "'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

 

Doesn't JS need a semicolon thought? You only end the line in a single quote it seems. Make sure $rssticker->recent-post->subject is a string.

I changed to this..

 

<?php
echo "var pausecontent=new Array();";
echo "var rsstxt=" . $rssticker->recent-post->subject . ";";
echo "pausecontent[0]='rsstxt';";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>';";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>';";
?>

 

Now i'm getting "Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.