note 24175 rejected from function.fdf-set-javascript-action by hholzgra

From: Date: Thu, 20 Mar 2003 10:44:54 +0000
Subject: note 24175 rejected from function.fdf-set-javascript-action by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-45541@lists.php.net to get a copy of this message
How to access JavaScript variables in PHP code: <br><br> It appears that there is no straight forward way of doing this. I have come out with a small trick to acomplish this as shown below. <br><br> Save the following code as test.php and run it. <br><br> <html> <body> <?php $php_var = 1; echo "Original value: $php_var"; if(isset($form_var) && !empty($form_var)) { $php_var = $form_var; echo "<br>After receiving value from JS variable: $php_var"; } else { ?> <form action="test.php" method="post" name="form1"> <input type="Hidden" name="form_var"> </form> <script language="JavaScript"> var js_var = 5; document.form1.form_var.value = js_var; document.form1.submit(); </script> <? } ?> </body> </html> The output will be: Original value: 1 After receiving value from JS variable: 5

« previous php.notes (#45541) next »