embedding javascript in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nicecandy
Forum Newbie
Posts: 1
Joined: Sat Dec 04, 2010 12:56 am

embedding javascript in php

Post by nicecandy »

i want to change the content of my div tag dynamically using javascript in PHP. I am using the following technqiue but it is not working.
<?php
echo "<script type='text/javascript'>\n";
echo "document.getElementById('mydiv').innerHTML = 'contents of div.......';";
echo "</script>";

?>

Plz guide me how can i do this

Thanks,

Best Regards,
Nice Candy.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: embedding javascript in php

Post by Christopher »

Since there are no variables to expand in the code you showed above, there is no need to use PHP. You can put that script outside the <?php ?> tags.
(#10850)
User avatar
awebtech
Forum Newbie
Posts: 21
Joined: Sun Nov 07, 2010 4:54 pm
Location: Russian Federation

Re: embedding javascript in php

Post by awebtech »

And also make sure that the div with id ''mydiv" is actually fully loaded BEFORE the JS-snippet execution.
Post Reply