Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting PHP...quick quest

Status
Not open for further replies.

alphacooler

Programmer
Aug 29, 2005
73
US
How do I correctly print php code in javascript? I.E.

document.getElementById('photosDiv').innerHTML = '<img src=" echo $row['path'];?>">';

does not work. I can output html just fine, but as soon as I try to output PHP code on a page my javascript stops working. I also tried escaping the ";" with "\" and that didn't do it.

Thanks so very much.
 
You can't output PHP in JavaScript. PHP is a [!]server-side[/!] lannguage, which means it runs oon the server, before the browser even gets a sniff at the page.

JavaScript is (few caveats aside) a [!]client-side[/!] language, which means that all server-side parsing will already have been done at the point the code is delivered to the page.

Ask in the PHP forum if you need more help with your PHP syntax.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I think we are talking about different things. I am using .innerHTML to insert HTML (and hopefully some PHP) into a PHP page. The PHP won't be executed until it gets outputted on the PHP page (obviously).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top