www.webdeveloper.com
Results 1 to 4 of 4

Thread: Passing Javascript variable to PHP Page

  1. #1
    Join Date
    Feb 2011
    Posts
    5

    Passing Javascript variable to PHP Page

    Here's my issue, I have this form name survey which have a textfield named: email on it

    <form name="survey">
    <label id="email">Email:</label><input id="email" type="text">
    </form>

    Email is store into a global variable in javascript.

    <script>
    var email = survey.email.value;
    function openwindow() {
    window.location.href = "test.php?email=" + email;
    }
    </script>

    Now I have another button that suppoused to be executing function openwindow():

    <input name="button" type="button" onClick="openwindow();" value="Send to PHP">

    For some reason it is not happening, it stays in the same window and nothing change.

    It needs to send the variable email to the PHP page so I can print it there:

    The code for test.php is the following:

    <?php
    echo "<h1>Your Email is:</h1>";
    echo "Email : ".$_GET['email']."<br>";
    ?>

  2. #2
    Join Date
    Feb 2011
    Posts
    5
    Just to let you guys know It now executes the test.php but the url is showing this:

    /test.php?email=undefined <----why is not passing?

  3. #3
    Join Date
    Oct 2010
    Posts
    18
    Have you tried the following.

    Code:
    <script>
    function openwindow() {
      var email = survey.email.value;
      window.location.href = "test.php?email=" + email;
    }
    </script>

  4. #4
    Join Date
    Feb 2011
    Posts
    5

    Yeap

    Yes I've tried that too, I declare the variable emaila s global so I can use it better inside any function.
    Any other idea?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles