#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    3
    Rep Power
    0

    Need help with a javascript in a form


    Hello All!
    I am very new to this forum and new to javascript, but I need your help.

    Heres what I want to do: I want to use javascript to copy the contents my users type into one form and have them copy to a number of other forms.

    Example: User adds address and email in first form they then click submit and that data fills in the other forms. They have top be individual forms because I then want them to submit each form individually.

    Any help would be appreciated as Im totally fizzed out on this one.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    25
    If the user submits the form, and the page changes then there are two ways to store the data:

    As cookies,
    In a server-side table.

    Possibly the best way to do it is in a table, simply generate a unique id, using uniqid() in PHP based on microtime(). Then store the data you've gathered in the table with that unique id as a primary key. Put the unique id as a query in the url, eg:

    form2.php?id=24762174

    and then each page can look up the data in the table and retrieve the necessary data and fill in the form.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    3
    Rep Power
    0
    Thankyou for your reply, but I was hoping that I could acheive this using javascript.

    I have been told it is quite simple doing it in javascript, but so far no one has really lead me in the right direction.
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    25
    In javascript only. Right then, there are ways of doing it, so that's good. One way is to set all the data as cookies. Then retrieve that data from the cookies using javascript.

    Getting the data into the cookies is easy.

    document.cookie = "name=" + escape(name)

    where the variable name holds the name value.

    Getting it back is more complicated.

    name = document.cookie.substring(document.cookie.indexOf("name=") + 5, document.cookie.length)

    then further manipulations to get the exact part.

    The other way is to use frames, then store all the form data in the parent frame as variables. Load the site into a 100% high/wide frame so that it doesn't look like it uses frames. This way the data will always be accessible as parent.name or something similar.

IMN logo majestic logo threadwatch logo seochat tools logo