SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing values from one page to another

    I would like to maintain a value in a form when a user clicks a link to a new page.

    I understand this can be done with a cookie but I have also read you can do this with hidden form fields. Can anyone tell me how the hidden form field method is coded/HTML'd?

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way you do it is by constructing a pseudo query string from a form containing hidden elements with the GET method. The data that you want to persist will get encoded as a string on the end of the URL so on each page you parse out the data from the url and document.write it into another invisible form field.

    For instance:
    Code:
    <form method=get action="page_2.html">
    <input type=hidden name="f1" value="foo">
    <input type=hidden name="f2" value="bar">
    <input type=submit>
    </form>
    This creates a url something like:
    Code:
    http://www.yourdomain.com/page_2.html?f1=foo&f2=bar
    Now you are on page two, and you can get at all the data that you wanted from page one by splitting up the window.location.href into little pieces and writing them back into page two's hidden form fields.

    This can also be accomplished completely without forms, using only JavaScript functions to handle navigation.

    Let me know if this doesn't make sense to you.
    <<< johnny chidiac
    johnnydaboy@mac.com

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Johnny, that makes sense but I don't think it will work for me, maybe the javascript method would.

    The problem being my form already has an action and submit that I can't change, I'm hoping to pass the value when the user clicks a hyperlink as opposed to a submit button.

  4. #4
    SitePoint Addict
    Join Date
    Mar 2001
    Location
    the windy city
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    take a look at the following tutorial from WA


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
  •