Re: PHP / JavaScript integration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux