Page 1 of 1

embedding javascript in php

Posted: Sat Dec 04, 2010 1:02 am
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.

Re: embedding javascript in php

Posted: Sat Dec 04, 2010 2:00 am
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.

Re: embedding javascript in php

Posted: Sat Dec 04, 2010 4:27 am
by awebtech
And also make sure that the div with id ''mydiv" is actually fully loaded BEFORE the JS-snippet execution.