View Full Version : passing javascript variables to php

08-21-2007, 05:47 PM
hi all

i am changing the variable value through javascript button click eg

function setMode()


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?

08-21-2007, 09:06 PM
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 (http://us3.php.net/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.

08-22-2007, 05:17 PM
hi this is



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





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

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


and this is

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


even then i am not getting the output on godaddy server

08-22-2007, 05:28 PM
Ok friends found the ****ing problem
had to use

$_REQUEST rather than $_GET

Can anyone tell whats the difference

08-22-2007, 11:52 PM
You can determine whether to use $_GET or $_POST by choosing "get" or "post" as your form's method.

You have:

<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.

08-24-2007, 04:40 AM
thanks dude