Passing the form data using JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • janu616
    New Member
    • Nov 2008
    • 1

    Passing the form data using JavaScript

    Hi all,

    I am new to this forum.I have started to work with JavaScript.
    I would like to know how do we pass the form data from one form and display the form values in the next page.
    And how does this change when we are using GET or POST?
    Looking forward for your help.
    Thanks in advance.

    Regards,
    Janu
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    to pass form data from one page to another you need a server side script (perl, php, asp,...) to process the data.
    POST and GET are defined in the form tag (html) and are not relevant to javascript.

    if you're new to javascript, then i recommend reading a tutorial (google(javascri pt tutorial))

    regards

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      you can pass values between pages using the queryString, no need for server scripts.

      most people use GET-style key/value pairs, but i actually prefer passing JSON.
      it's simpler to decode (just use eval), and can be more efficient.
      you just need a simple loop to build the json from the form.

      something like:

      "({"+
      loop: ( elm.name +":'"+elm.value +"'") // (join with ",")
      +"})"

      then just tack that onto the URL of the new page after a "?".

      in the new page, you can eval(location.s earch.substr(1) ) to get your object back.


      EDIT: forgot about one thing. while my script works across domains, if both pages are on the same site, you can simply use cookies to pass data. one page's cookie will be there for another page on the same site.

      Comment

      Working...