[Fwd: Re: [PHP] PHP / JavaScript integration]

2005-03-09 Thread Jochem Maas
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:[EMAIL PROTECTED]
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


Re: [PHP] PHP / JavaScript integration

2005-03-09 Thread Richard Lynch

 Hi,

 I'm trying to integrate some JavaScript functions in PHP, but so far, no
 good :(

 I want to have a js.php file that has the JavaScript functions i want to
 use. This file, albeit its extension, has no PHP code or even tag.

 It's just like this:

 js.php
 --
 script language=JavaScript

 function def(word) {
  if (word == 'all_not_filled') {
  type = 'error1';
  definition = 'You didn't filled all form fields.';
  }
 myFloater =
 window.open(filename,'myWindow','scrollbars=no,status=no,width=300,height=200')
 }

 /script
 --

 Now... i want to call this JavaScript function from the regular PHP files.
 In particular, before the HTML code.
 Like this:

 index.php
 --

 ?php

   if (condition)
def('all_not_filled') // def is a JS function in js.php

You can't do that.

You could do this:
?php
  require 'def.js';
  if (...) echo def('all_not_filled');;
?

Then, when the page gets sent to the browser, the def() function gets
called by the browser.

PHP runs on your server.

JavaScript is run by the browser, on the web surfer's computer, millions
of miles away, and long after PHP has finished its work and gone away.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP / JavaScript integration

2005-03-08 Thread Mário Gamito
Hi,
I'm trying to integrate some JavaScript functions in PHP, but so far, no 
good :(

I want to have a js.php file that has the JavaScript functions i want to 
use. This file, albeit its extension, has no PHP code or even tag.

It's just like this:
js.php
--
script language=JavaScript
function def(word) {
if (word == 'all_not_filled') {
type = 'error1';
definition = 'You didn't filled all form fields.';
}
myFloater = 
window.open(filename,'myWindow','scrollbars=no,status=no,width=300,height=200')
}

/script
--
Now... i want to call this JavaScript function from the regular PHP files.
In particular, before the HTML code.
Like this:
index.php
--
?php
 if (condition)
  def('all_not_filled') // def is a JS function in js.php
?
HTML
 HEAD
(...)
/HTML
--
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 :(
Any help would be apreciated.
Best regards,
Mário Gamito
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PHP / JavaScript integration

2005-03-08 Thread Gabe Guzman
On Wed, Mar 09, 2005 at 12:27:39AM +, M?rio Gamito wrote:
 Hi,
 
 I'm trying to integrate some JavaScript functions in PHP, but so far, no 
 good :(
 
 I want to have a js.php file that has the JavaScript functions i want to 
 use. This file, albeit its extension, has no PHP code or even tag.
 
 It's just like this:
 
 js.php
 --
 script language=JavaScript
 
 function def(word) {
 if (word == 'all_not_filled') {
 type = 'error1';
 definition = 'You didn't filled all form fields.';
 }
 myFloater = 
 window.open(filename,'myWindow','scrollbars=no,status=no,width=300,height=200')
 }
 
 /script
 --
 
 Now... i want to call this JavaScript function from the regular PHP files.
 In particular, before the HTML code.
 Like this:
 
 index.php
 --
 
 ?php
 
  if (condition)
   def('all_not_filled') // def is a JS function in js.php
 
 ?
 
 HTML
  HEAD
 
 (...)
 
 /HTML
 --
 
 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 :(

why not use a script include instead of a php one?  ie: 

script language=javascript src=js.php

from inside your index.php page? 
seems to make sense, since there is no php in the js file.  
just a thought, 
gabe.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP / JavaScript integration

2005-03-08 Thread Chris W. Parker
Mário Gamito mailto:[EMAIL PROTECTED]
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 :(

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.

It's a bit confusing at first but once you understand it, you'll wonder why it 
ever didn't make sense.



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php