when developing sites, sometimes we need to get some of variables, like users screen resolution and others. PHP can not obtain screen resolution, but you can do this with javascript. and the main thread's idea is how to pass variable from javascript to php!
Did you get dat ?
is there any way to make php and javascript talk?
-
- Posts: 987
- Joined: Sun Feb 26, 2006 4:56 pm
- Contact:
-
- Posts: 31
- Joined: Thu Mar 23, 2006 6:51 am
The simplest answer I can concieve to this question is as follows:
PHP is initialised before the page is load, and writes it's own code (HTML) into the page.
Therefore, if you include JavaScript code in an echo or a variable that becomes part of the HTML source for the page, that JavaScript will become active once the page has loaded.
Like kaos said, one is active only while the other is inactive, however, that does not mean that code from one cannot **** code in another. I.e. if you have a JavaScript where the code requires a variable x, then you can have PHP determine what the value of x is before the JavaScript is loaded. :twisted:
PHP is initialised before the page is load, and writes it's own code (HTML) into the page.
Therefore, if you include JavaScript code in an echo or a variable that becomes part of the HTML source for the page, that JavaScript will become active once the page has loaded.
Like kaos said, one is active only while the other is inactive, however, that does not mean that code from one cannot **** code in another. I.e. if you have a JavaScript where the code requires a variable x, then you can have PHP determine what the value of x is before the JavaScript is loaded. :twisted:
-
- Posts: 24
- Joined: Thu Jun 01, 2006 3:22 pm
You know thev way you can go www.mydomain.com/index.php?var="value"? Javascript can set/read the stuff after the question mark, too. Look on google for more info on how to do it.
I use an invisible iframe (0x0) that can be used to "AJAX-like" functions.
JS can be used to POST / GET and making it "talk" with PHP is like making the user "talk" with PHP
JS can be used to POST / GET and making it "talk" with PHP is like making the user "talk" with PHP
Code: Select all
define('I_LOVE_PHP', true);