Re: php and js variables
| From: | Ernest E Vogelsinger | Date: | Sun, 04 May 2003 11:29:54 +0000 |
| Subject: | Re: php and js variables | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146340@lists.php.net to get a copy of this message | ||
At 08:27 04.05.2003, Paul Marinas said:
--------------------[snip]--------------------
>Is there a way to get the value of a javascript
>variable and put it into a php variable?
--------------------[snip]--------------------
JS is client-side, and PHP is server-side. This implies you must transmit
the JS value to the server somehow, usually as a form element, or via URL.
an example (untested, most certainly you need to fiddle around a bit):
<script>
var client_side_var = 4711;
function submit_this(form)
{
hidden = form.elements['client_side'];
if (hidden) hidden.value = client_side_var;
}
</script>
<!-- some more header/body/etc, then the form: -->
<form action="myscript.php" onSubmit="submit_this(this);">
<input type="hidden" name="client_side" />
<input type="submit" />
</form>
Upon submit, the provided JS function gets be executed. It fills the hidden
form element with the contents of the JS variable, so you have it available
in myscript.php as $_REQUEST['client_side'].
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/