Re: using php with java script
| From: | Stephen Hui | Date: | Wed, 05 Jul 2000 15:05:35 +0000 |
| Subject: | Re: using php with java script | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4972@lists.php.net to get a copy of this message | ||
> As a matter of fact, you can. Because of the way php is placed inside your
> html document, nothing prevents you from giving js variables values from
> php
This is exactly correct.
While your PHP script is generating HTML, it can also generate
Javascript code and initialize Javascript variables with PHP variable
*values*. Meaning you could initialize a Javascript variable like this:
<?php
echo " var js_var = [value of $php_var]";
?>
or alternatively (as Markus pointed out)
var js_var = <?php echo $php_var; ?>
Either method inserts into the HTML stream
var js_var = [value of $php_var]
To go from Javascript to PHP, however, requires traditional HTML form
elements with a submit function being called ("this.form.submit()" or a
submit button) with a POST or GET method and ACTION pointing to the PHP
script; or a URL-encoded query string appended to the URL of the PHP
script:
http://www.somewhere.com/script.php?name1=value1&name2=value2&...&nameN=valueN
I've coded sites this way before, and it's the only way I know of to
pass variables and their values between Javascript and PHP.
Hope this helps.
Stephen
--
Stephen Hui, ARL:UT, Austin, Texas
Computer Terms: Programmer - A red-eyed, mumbling mammal
capable of conversing with inanimate objects.