I needed to pass a variable to PHP through Javascript. Does anyone have any ideas on how to do this?

Thanks

    You can do this with HTML. I'm not familiar with java, but mabey you can think of a way to incorperate this with php.

    When you make a HTML text box, the name becomes the variable.

    Say you made a HTML form with a text box and a submit button. after you submit the form, and it takes the info...

    < input type="text" name ="namehere">

    That would make the variable $name="namehere";

    you konw what i mean? hope you can find a way to put that with java, good luck.

      How are you trying to pass the variable? Through a link to another php file? Onload of the page?

      If its through a link, try something like this in JS:

      var domain = "www.nowhere.com";
      var v = "somevar";
      document.write("<a href=\""+ domain +"/file.php?"+ v +"\">");

      I don't think that you can transfer a JS variable with out a link or a form. I hope that helps.

        <?
        if(isset($REQUEST['start_var'])){$start_var=$REQUEST['start_var'];}

        if(isset($REQUEST['receive_var1''])){$receive_var1'=$REQUEST['receive_var1''];}

        echo "posted var - $receive_var1'";
        ?>

        <html>
        <head>
        <script language='javascript'>

          operatevars()
          function operatevars()
          {
            //do somethinf with your vars
            var iii = 222;
                  document.form_name.receive_var1.value=YOURVARIABLE(iii)       
        
                 document.form_name.submit();
          }

        </script>

        </head>
        <body>

        <form name='form_name' method='post'>
        <input type=button onclick='operatevars()'>
        <input type=text name='receive_var1'>
        <input type=text name='receive_var2'>
        <input type=hidden name='start_var' value='1'>
        </form>

        </body>
        </html>

          you can't have javascript communucate directly with php... javascript can't go outside the browser....

          however the best you can do is described above in the last post

          document.forms.formName.inputName.value='something'
          

          you can have javascript change form values as the user goes through the page... i know this is what forms do anyway, but you can have a hidden variable and have js write a value to that.

          so when the form IS submitted it will be different than the form php wrote when sending it to the user.

            Hi !!

            directly not... that's sure... but u can code a workaround with loading xml files via JavaScript. Behind this xml-files there is a php-Script that do things for u, which u give datas via the GET-method.
            I've tested it for me, and it works. No reload, but dynamic variables and I'm also able to edit things on the fly.

            Maybee there is a securehole, but for testing it works...
            It only works on newer Browsers. I've tested it on IE5.5 and NS7.0...

            Hope that will help u... and don't laught about my english .. 😉

            greetz Stuck

              Write a Reply...