...

View Full Version : passing javascript variables to php



thindrakhya
08-21-2007, 06:47 PM
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?

Fumigator
08-21-2007, 10: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.

thindrakhya
08-22-2007, 06:17 PM
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

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

$_REQUEST rather than $_GET

Can anyone tell whats the difference

Fumigator
08-23-2007, 12:52 AM
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.

thindrakhya
08-24-2007, 05:40 AM
thanks dude



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum