jd2007 Posted July 25, 2007 Share Posted July 25, 2007 function name() { <?php // some code ?> } Quote Link to comment 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). Quote Link to comment Share on other sites More sharing options...
calabiyau Posted July 25, 2007 Share Posted July 25, 2007 nevermind...you go it covered. EDIT Quote Link to comment 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!! Quote Link to comment Share on other sites More sharing options...
plutomed Posted July 25, 2007 Share Posted July 25, 2007 It normally causes errors Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 25, 2007 Share Posted July 25, 2007 only if you do it wrong Quote Link to comment 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 ? Quote Link to comment 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>'; Quote Link to comment 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... 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.