PDA

View Full Version : how we can take $_post variable in javascript code???



MSK7
06-26-2009, 06:53 AM
Hello all ,

I have two forms. one in which i will fill value & after submitting

this $_Post['value'] , this value will go in to the next page.

But i need this value on next page in my javascript code also .

when i use this value in javascript by storing it in a variable "abc"

like :-



var abc="<?php echo $_POST['adult']; ?>";

alert(abc);



then it shows in alert the script "<?php echo $_POST['adult']; ?>";

rather than the value of php variable stored .




please suggest me some solution regarding these so that the JS alert shows

the value of php variable stored , rather than the php script used .



Thanks & Regards.

Snookerman
06-26-2009, 07:38 AM
I think that might be because PHP is server side and JavaScript is client side so the PHP code executes on the client side in your example, causing it to just alert everything. I'm not sure though.

bluewalrus
06-26-2009, 01:01 PM
or maybe this


$message = $_POST['adult'];
echo "<script type=\"text/javascript\">\n"; echo " alert(\"$message\");\n"; echo "</script>\n\n";

ss25
11-16-2009, 08:53 PM
Hello all ,

I have two forms. one in which i will fill value & after submitting

this $_Post['value'] , this value will go in to the next page.

But i need this value on next page in my javascript code also .

when i use this value in javascript by storing it in a variable "abc"

like :-



var abc="<?php echo $_POST['adult']; ?>";

alert(abc);



then it shows in alert the script "<?php echo $_POST['adult']; ?>";

rather than the value of php variable stored .




please suggest me some solution regarding these so that the JS alert shows

the value of php variable stored , rather than the php script used .



Thanks & Regards.
var x=document.getElementById("ur location").value
if(condition)
{
alert("MSG");
}

Try this code,it may helpful..

abumalek
01-29-2011, 04:38 PM
I want the same thing, but i got the same result ==> it shows in alert the script "<?php echo $_POST['adult']; ?>";


Can u tell me what do u mean by "ur location" !!!

did u find the solution ???

fileserverdirect
01-30-2011, 08:46 PM
Is that page a .php page?