converting a javascript variable to php variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumanbangladesh
    New Member
    • Sep 2007
    • 4

    converting a javascript variable to php variable

    hi
    I am new both in php and javascript. I have a javascript varialbe. But I need a php variable with the same contents.How can I do it.

    thanks in advance
  • bnashenas1984
    Contributor
    • Sep 2007
    • 257

    #2
    I think you can do it by using javascript functions. something like this

    Code:
    <script language="javascript">
    function test(testvar)
    {
    
    }
    </script>
    <body onload="test('<?PHP print $sendvar; ?>')"
    </body>
    Here's an example.. And on line number 4 you have a variable called testvar with the same value as $sendvar in your php script

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Originally posted by sumanbangladesh
      hi
      I am new both in php and javascript. I have a javascript varialbe. But I need a php variable with the same contents.How can I do it.

      thanks in advance
      Ok you have a javascript variable. And what is this "php variable with the same contents"? can you show us any example, because I can't understand what you are trying to do.

      Comment

      • bnashenas1984
        Contributor
        • Sep 2007
        • 257

        #4
        Oh sorry I think what I tried to explain was exactly the oposite .. That's what I was looking for , for a long time.
        But now I know what you mean.. Having a php variable with the same value as a java variable

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, sumanbangladesh .

          You have three options:
          • Use cookies.
          • Use AJAX.
          • Set the value of a hidden input in a form and submit the form.


          Note that in all three cases, you are sending data to the server (the cookie value gets sent to the server with the next page load).

          Comment

          Working...