Page 1 of 1
How to get variable from javascript env. and use for PHP?
Posted: Thu Oct 07, 2004 2:23 am
by Ruzanna
Hello everyone,
Please help me, I begginer and can't solve one question.
How can I get variable from javascript environment and use for php variable?
Beforehand thankfull,
Ruzanna
Posted: Thu Oct 07, 2004 2:43 am
by twigletmac
PHP could only access the variable if you refreshed the page and passed it via POST (e.g. a form), via GET (ie. in the URL) or in a cookie.
Mac
hidden
Posted: Thu Oct 07, 2004 2:49 am
by phpScott
you would have to use hidden fields in your html form and use javascript to set that field then the value would be passed when the form gets submited.
then it would be like twig said
...
Posted: Thu Oct 07, 2004 3:48 am
by Calimero
Or, is this what you meant:
Code: Select all
<?php
$variable = "<script language"javascript">document.write(JavaScript_variable);</script>";
...
?>
NOTE - JavaScript_variable first needs to be declared inside the JavaScript so you could "write it" inside the php.
like this:
Code: Select all
<script language"javascript">
JavaScript_variable = document.form_name.field_name.value
</script>
fill the
form_name = with the name of your form
and
field_name = with the field you want to pass
NOTE - this is the code only if the JavaScript and PHP are on the same page.
Hope this helps.
Posted: Thu Oct 07, 2004 4:05 am
by patrikG
twigletmac wrote:PHP could only access the variable if you refreshed the page and passed it via POST (e.g. a form), via GET (ie. in the URL) or in a cookie.
Mac
Basically, yes - but the lines are blurring:
http://www.sitepoint.com/blog-post-view.php?id=191776
http://www.sitepoint.com/blog-post-view.php?id=192138
http://www.sitepoint.com/blog-post-view.php?id=193677
Posted: Thu Oct 07, 2004 6:34 am
by phpScott
like I still don't have enough to figure out with XML now you have to go and throw this into the works. Thanks patrickG.
I been using the IFRAME method for a while and it does work providing you are willing to do lots of coding in JS. It is fairly straigth forward but referencing around the different windows can get tiresome.