Re: javascript var on a php var...

From: Date: Fri, 06 Jul 2001 15:16:35 +0000
Subject: Re: javascript var on a php var...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-56496@lists.php.net to get a copy of this message
Romeo Manzur wrote: > > hi, I want to know how could I save a javascript variable on a php > variable??? > Thanks... It depends how the user will get to the php page: 1. Form If the user is about to submit a form and you want some Javascript variable from your page to end up as a php variable after the form is submitted then: Create a hidden form variable e.g. <INPUT TYPE=HIDDEN NAME="myvariable"> Set this formvariable to your Javascript variable in the Javascript e.g. document.form.myvariable.value = myjavascriptvariable; After submission $myvariable will be a php variable in the target page with the value you gave it. 2. Link If you want to set a php variable in a page which the user will get to by a link, then you need to add a GET query to the link e.g. your Javascript will have something like this: document.myhref.location = document.myhref.location+"?myvariable="+myjavascriptvariable; i.e. the link becomes myoriginallink?myvariable=... php will automatically become up the value you specify and set $myvariable to that value. George

« previous php.general (#56496) next »