Zand Php Cake Php

Posted by : Phper
How to access a Javascript value in PHP code?
Any idea?
 
 
Posted by : Felipe Nascimento de Moura
Re : How to access a Javascript value in PHP code?
javascript runs on client side ... php, on server side ... to interact
them, you must create or simulate a new connection to the server. Send
data from js to PHP, or write js to your client.

Think about ajax
 
 
Posted by : TJ
Re : How to access a Javascript value in PHP code?
To pass a javascript variable into php, use a FORM POST with auto-

submit since JavaScript code cannot be embedded into PHP code.  Here

is an expample using an a html form with an auto-submit.  This method

requires two files, the first called as the webpage to begin the

process, and the second as the answering page to demonstrate that the

javascript variable has be captured by the server's php cache.



For example, name the first file javascript_var_to_php.htm as the

first webpage called, with the following code:





<form ID="variable_pass" name="javascript_variable_to_
php_variable"

action="variable_capture.php" method="post">



    <script type="text/javascript">



         var javascript_variable = "javascript_string_or_value";

         document.write ("<input type='hidden'

name='javascript_variable' value='"+javascript_variable+"'>");



    </script>



</form>





<script type="text/javascript">



    document.forms("variable_pass").submit()



</script>





Then, the information is passed to the php in the server and can be

demonstrated with the following file -- call it variable_capture.php

-- saved in the same folder as the first, with the following code:





<?php



    $php_variable_from_javascript_variable = $_POST

['javascript_variable'];



    function display_captured_js_var_into_php()

    {

         global $php_variable_from_javascript_variable;

         echo ("The JavaScript variable 'javascript_variable' passed

to the PHP ")

         echo ("variable '\$php_variable_from_javascript_variable' is

the string '");

         echo ($php_variable_from_javascript_variable);

         echo ("'.");

    };



    display_captured_js_var_into_php();



?>





==========================================================





To capture a PHP variable into JavaScript, on the other hand, simply

embed the PHP code into JavaScript tags.  As an example, call up the

webpage coded with a file -- call it php_var_to_js.php -- with the

following code:



<?php



    $php_variable = "php_string_or_value";



?>





<script type="text/javascript">



    var javascript_variable_from_php_variable = "<?php  echo

$php_variable  ?>";

    document.write ("The PHP variable '$php_variable' passed to the

JavaScript ") +

    document.write ("variable 'javascript_variable_from_php_variable'

is the ") +

    document.write ("string '" +

javascript_variable_from_php_variable + "'.");



</script>





==========================================================





luck,

TJ
 
 
Posted by : crimaniak
Re : How to access a Javascript value in PHP code?
Variables available both client-side and server-side are called

'Cookies'.
 
 
Posted by : Brian Hodgins
Re : How to access a Javascript value in PHP code?
The cookie method and POST are probably your best bets. But do keep in

mind, this might cause a significant slowdown when you load pages. Be

careful of infinate loops with using POST.
 
 
Posted by : I Ketut AC PRATAMA
Re : How to access a Javascript value in PHP code?
Hi,

To access Javascript value in PHP you can do the following trick:
you have to register the Javascript value as session and then use PHP script to access the session that just registered.

hope can help.


thx
 
 
If you have the better reply, then send it to us. We will display your reply after the approval.
Name : 
Email Id :   
Reply :