this post was meant for the OP - I sent it to Chris W. (only) by mistake. oops....
-------- Original Message -------- From: - Wed Mar 09 19:50:29 2005
Chris W. Parker wrote:
Mário Gamito <mailto:lists@xxxxxxxxxxx> on Tuesday, March 08, 2005 4:28 PM said:
I'm trying to integrate some JavaScript functions in PHP, but so far, no good :(
[snip]
Now... i want to call this JavaScript function from the regular PHP files. In particular, before the HTML code. Like this:
[snip]
How can i do this ? How to tell PHP, that def(word) is a JS function in js.php file ? I've tried include ('js.php'), etc., but got no results :(
include ('js.php') will output the contents of that file to the browser, assuming include() actually finds the file.
You don't and you can't. PHP does not interact with the client (like you are thinking it does) and Javascript does not interact with the server. They are completely different and not related, except that PHP can send Javascript to the client for the client to interpret.
javascript is a scripting language, there is no theoretical reason that it can't be used as a serverside scripting language, but the fact that practically nobody in the real does says something :-). anyway its not strictly correct to say javascript is 'clientside'.
as for calling a javascript function directly from php code, forget about it.
It's a bit confusing at first but once you understand it, you'll wonder why it ever didn't make sense.
1 round trip:
1. a (php) webserver gets a request for a page. 2. the server runs the requested (php) script. 3. the server sending some output to the browser. 4. the browser interprets the output.
the output is generally a webpage - this can include <script> tags that contain/include javascript. when the page is parsed and rendered by the browser the javascript you included will be run.
Chris.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php