SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting GET or POST variables using JavaScript

    I have something that runs on a server with no PHP or any of those widgets.

    A user submits a form with 6 fields. Clicks "Go". A page appears that displays what he just entered, with a form of his data in hidden fields, and a link with document.form.submit() that takes you to a CGI program. It must be 2 different page loads.

    Is displaying what he entered in the form in the next page possible with JavaScript? If so, what are the JS variables that would let me access that data?

    Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,140
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    js to display vars

    The server may not have PHP, but CGI (Perl) is what is getting the form's POST variables.
    I know of no way for javascript alone to get and display POST variables that where sent to it's page.
    However, javascript can parse GET variables out of the location object if you don't mind having everything visible in the URL and aren't worried about security issues.
    Or you could use javascript to display the entered information before the form is submitted. Something like a "You entered the following information. Are you sure you want to submit it?" type of thing.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,799
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you use GET then Javascript can read the values that are passed using window.location.search.

    See http://javascript.about.com/library/blqs1.htm for more info on how to do it.

    Javascript has no access if you use POST
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice article, I came up with a similar method today. Came across this page on google, just thought i would share it:

    http://failchad.blogspot.com/2009/01...avascript.html
    TinyURL can suck a W33 Peen


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
  •