Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts

    passing javascript variables to php

    hi all

    i am changing the variable value through javascript button click eg

    function setMode()
    {
    document.FrmMaster.hidEditVariable.value='DC';

    document.FrmMaster.submit();
    }


    this works fine when i am using on localt host using apache
    now i have uploaded the files on godaddy and my variables like
    hideditvariable is not chnaged when i click on the buttons
    i don't know what setting needs to be changed for webserver as it works on loal host

    one thing more ,
    initially i was using variables like $abc on php
    but this did'nt work on godaddy i had to use $_GET["abc"] to work on godaddy
    i dont' know why?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Without the rest of your script there's no way of knowing why it wouldn't be working.

    Using $abc rather than $_GET['abc'] is bad practice because of what you experienced; a server can turn register_globals off (because it can be a massive security hole) and your script breaks. So it's obviously better to specify $_GET['abc'] as a standard.

  • #3
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    hi this is

    testing1.html

    <html>
    <body>

    <SCRIPT language="JavaScript">
    function setMode()

    {


    document.form1.var1.value='D';
    document.form1.submit();

    }

    </script>

    <form ACTION = "testing1.php" METHOD = post NAME = "form1" >

    <input name = "var1" type = "hidden" value = "B">
    <input type ="button" onClick = "setMode();" value = "Enter Information">

    </form>
    </body>
    </html>


    and this is
    testing1.php


    <?php
    echo($var1); or echo($_GET["var1"]);
    ?>




    Now When i run on my local host this runs fine but when i run on my godaddy server the output is nill, i dont' know why




    one thing more i have tested by simly echoing the value of hidden variable var
    i.e without this

    document.form1.var1.value='D';
    even then i am not getting the output on godaddy server
    Last edited by thindrakhya; 08-22-2007 at 06:22 PM.

  • #4
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Ok friends found the ****ing problem
    had to use

    $_REQUEST rather than $_GET

    Can anyone tell whats the difference

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can determine whether to use $_GET or $_POST by choosing "get" or "post" as your form's method.

    You have:
    Code:
    <form ACTION = "testing1.php" METHOD = post NAME = "form1" >
    Your form is method="post" so your form elements will be available in the $_POST array in PHP when it is submitted. Both $_GET and $_POST arrays are also defined in the $_REQUEST array but I always prefer using $_GET or $_POST for clarity.

  • #6
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    thanks dude


  •  

    Posting Permissions

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