nicecandy Posted December 4, 2010 Share Posted December 4, 2010 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. Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted December 4, 2010 Share Posted December 4, 2010 I don't see any reason why that wouldn't work, can you provide some of your html as well? Quote Link to comment Share on other sites More sharing options...
nicecandy Posted December 4, 2010 Author Share Posted December 4, 2010 the html code is as follows <body> <div id="mydiv"></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 4, 2010 Share Posted December 4, 2010 Bit confusing, since you can use javascript/html/cssinterchangeably in the middle of php files it seems to make no sense to echo out javascript commands, why not just do something like the following: <?php php code here..... ?> <script type='text/javascript'> document.getElementById('mydiv').innerHTML = 'contents of div.......'; </script> <?php more php code here ?> Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted December 4, 2010 Share Posted December 4, 2010 do you echo your javascript before or after the html? The way you have inserted the javascript, not in a function or anything like that, it is going to run right when the browser processes it, so if you have it before your div has been parsed then you will get an undefined object. And Zurev does have a point, I have to assume that this is just a proof of concept type thing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.