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? Quote 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? Quote 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> Quote Link to comment https://forums.phpfreaks.com/topic/164836-php-in-javascript/#findComment-869199 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.