jd2007 Posted July 25, 2007 Share Posted July 25, 2007 function name() { <?php // some code ?> } Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/ Share on other sites More sharing options...
btherl Posted July 25, 2007 Share Posted July 25, 2007 Hmm. You cannot have php code that executes within javascript. But you can use php to dynamically generate code that is later executed by javascript. If you want to execute php code after the javascript has begun execution, then you need to use ajax techniques to call the php code on the server. The reason for all this is that php is server side and javascript is client side (it runs in your browser). Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-306959 Share on other sites More sharing options...
calabiyau Posted July 25, 2007 Share Posted July 25, 2007 nevermind...you go it covered. EDIT Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307060 Share on other sites More sharing options...
ToonMariner Posted July 25, 2007 Share Posted July 25, 2007 You can how ever use php to construct the javascript!! Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307064 Share on other sites More sharing options...
plutomed Posted July 25, 2007 Share Posted July 25, 2007 It normally causes errors Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307094 Share on other sites More sharing options...
ToonMariner Posted July 25, 2007 Share Posted July 25, 2007 only if you do it wrong Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307485 Share on other sites More sharing options...
jd2007 Posted July 26, 2007 Author Share Posted July 26, 2007 how to use php to construct javascript ? Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307598 Share on other sites More sharing options...
btherl Posted July 26, 2007 Share Posted July 26, 2007 The same way you use php to construct html. There's a few different styles of that. For example print '<script type="text/javascript">"; print 'alert('Hi there');'; print '</script>'; Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307631 Share on other sites More sharing options...
ToonMariner Posted July 26, 2007 Share Posted July 26, 2007 print 'alert('Hi there');'; should be print 'alert(\'Hi there\');'; or print "alert('Hi there');"; which is why that fails... Link to comment https://forums.phpfreaks.com/topic/61664-is-it-possible-to-embed-php-within-a-javascript-function-like-below/#findComment-307996 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.