Results 1 to 6 of 6

Thread: how we can take $_post variable in javascript code???

  1. #1
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question how we can take $_post variable in javascript code???

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

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    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.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    or maybe this

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

  4. #4
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by MSK7 View Post
    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 :-
    Code:
    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..

  5. #5
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

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

  6. #6
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Is that page a .php page?
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

Bookmarks

Posting Permissions

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