Results 1 to 3 of 3

Thread: PHP & Javascript variables...........

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298

    PHP & Javascript variables...........

    Hi,
    Is it possible to use Javascript variables in PHP code? I need to be able to assign the values of javascript variables to PHP variables.
    I am able to display the values using the alert statement. But how can these values be assigned to PHP variables?

    Thanx a lot.

    Here's my sample code:

    Code:
    <html>
    <head>
    <title>Test page</title>
    <Script language="javascript">
    var a;
    var a1 = new Array();
    
    function testfn()
    {
    	var i;
    	a='abc';	
    	for (i=0;i<=4;i++)
    	a1[i]=i;	
    }
    
    </script>
    </head>
    
    <body>
    <?php
    echo "<script language='javascript'>";
    echo "testfn();";
    echo "alert(a);";
    echo "alert(a1[2]);";
    echo "</script>";
    ?>
    </body>
    </html>

    Is it possible for me to assign the values of "a" and the array "a1" to PHP variables?? Thanx again.

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    I'm not giving the lecture again.

    I will sum up to say:

    The page will be created by the server-side technology (PHP) before it is sent to the client, where the client-side scripting will be instantiated.

    In other words, by the time a JavaScript variable is born, all of the PHP variables have died.

    You can "assign" the value of a PHP variable to a JavaScript variable simply because PHP is writing the page, and it can write a JavaScript variable declaration.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    rammy:

    Tell us exactly what you want to achieve and we'll provide a workaround.

    As it stands I can't see why you would want to be able to do this!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width