Rochtus Posted July 5, 2009 Share Posted July 5, 2009 Is it possible to put a little PHP code like this <script type="text/javascript> <?php $tester = $_POST['test']; ?> var helloworld = $tester; document.write(helloworld); </script> kweet ni zeker of dit script werkt, heb efkes snel geschreven maar zou dit principe werken? Link to comment https://forums.phpfreaks.com/topic/164836-php-in-javascript/ Share on other sites More sharing options...
Rochtus Posted July 5, 2009 Author Share Posted July 5, 2009 Is it possible to put a little PHP code like this <script type="text/javascript> <?php $tester = $_POST['test']; ?> var helloworld = $tester; document.write(helloworld); </script> I'm not sure the script is 100% correctg but would the way of working work? Link to comment https://forums.phpfreaks.com/topic/164836-php-in-javascript/#findComment-869160 Share on other sites More sharing options...
RichardRotterdam Posted July 5, 2009 Share Posted July 5, 2009 Is it possible to put a little PHP code like this <script type="text/javascript> <?php $tester = $_POST['test']; ?> var helloworld = $tester; document.write(helloworld); </script> kweet ni zeker of dit script werkt, heb efkes snel geschreven maar zou dit principe werken? It doesn't work that way. In your case PHP is serverside(on a webserver) and javascript runs clientside(within your browser). If you want to see how your javascript looks like use the "view source" option in your browser. It should be like this btw <?php $tester = $_POST['test']; ?> <script type="text/javascript> var helloworld = "<?php echo $tester; ?>"; document.write(helloworld); </script> Link to comment https://forums.phpfreaks.com/topic/164836-php-in-javascript/#findComment-869199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.