Re: php & javascript
| From: | burk at pobox dot com | Date: | Tue, 13 Jun 2000 10:48:32 +0000 |
| Subject: | Re: php & javascript | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1705@lists.php.net to get a copy of this message | ||
As other people have stated, it can't be done "smoothly", although they
told you how to move a php variable to javascript. To move a javascript to
php, the only way I have found is to use javascript to set the value of a
form element and submit it. Something like
echo "
<script language=javascript>
function passvar (MyVar) {
document.MyForm.elements[\"MyHidden\"].value=var;
document.MyForm.submit();
}
</script>
";
// and then in the body of the page
echo "
<form method=post action=\another.php\" name=\"MyForm\">
<input type=hidden name=\"MyHidden\" value=\"\">
</form>
";
// and then when you need to move the value of the javascript variable
// you call
echo "
<input type=button value=\"Move the Variable\" onClick=\"passvar(MyVar)\">
";
// now in the receiving page $MyHidden is var
This will work If And Only If
The client has javascript turned on AND
The client's browser supports javascript AND
You can tolerate a form submit to accomplish this
All in all, you should save javascript for when it's not important, or
when you really need it, and then you should test for it, or warn the user
that they need it.
HTH,
-burk
On Tue, 13 Jun 2000, sarahana wrote:
> Hi, I was wondering:
>
> How would you assign the value of a javascript variable to a php
> variable?
>
> gracias.
>
>
>
--
burk@pobox.com
Linux File Managers: http://www.pobox.com/~burk/linuxfile.html