SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Keeping values in a form...

    Hi there,

    I've written a combined Javascript/PHP application which allows a user to do some price calculation for magazine adds. Everything works fine except the back (zurück) option on the result page.

    What I would like to achieve is that when a user goes back to the first page that his/her selection of the cities is still available. All items that have been selected are in the right hand box. This list is again empty when they return to this page via the "history.go(-1)" link.

    The page is in dev status and in german, but it is very easy to understand, so it shouldn't be any problem for you guys. The javascript code can be seen in the source code on the first page. The left list is filled with a mySQL statement in the first place.

    Of course I can to some PHP workaround by evaluating the submitted variables, but this would be much more work. I want to know if there is an easier approach?

    "Wiederholungen" means repetition. Please just enter a number there

    The link to view the application is http://ihk.digital4u.de.

    Thanks for any input,

    bets rgerads,

    ASchweti

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your going to have to do it with php. The reason is that you are dynamically creating new options on the fly and the browser has no way of remembering the values this way. Think of it the same way as if you were to do an innerHTML on the page, you wouldn't expect the value to be there when you press the back button, same goes for dynamically creating form content as well. Dynamic content created with javascript is gone forever once you leave the page.

    Another way would be to use cookies but your better off putting the dynamic values in a hidden form element, pass it to the next page in post or get then you can have a persistence across both pages. Creating a session might even be a better solution.

    -xDev

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Die Grüße, ASchweti, wondered what happened to you.

    I'd go with a session too - you're using PHP as it is; but I disagree that "Dynamic content created with javascript is gone forever once you leave the page." Not if you use JS to store it somewhere. Not many hiding places on the client; a cookie would be the obvious choice. If you're not using a frameset (good thinking) there's another option: the window.name property. I've been fooling with this for ages, to good effect.

    I had knocked out a demo for you earlier, adapted from something similar, but didn't bother to post it here. Added the window.name 'persistence' to illustrate. Ignore the CSS. Sorry about the German.
    Attached Files Attached Files
    Last edited by adios; Dec 16, 2004 at 02:04.
    ::: certified wild guess :::

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Adios, hi xDev,

    thanks for your replies! I currently think I will go the PHP/Sessions way. Maybe because there I don't have to walk on thin ice

    I didn't get what you meant with this sentence...
    I had knocked out a demo for you earlier, adapted from something similar, but didn't bother to post it here. Added the window.name 'persistence' to illustrate. Ignore the CSS.
    I had so many helpfull hands here that I do not remember which demo you are talking about...

    Is your conclusion that it is possible, or that it would be easier to go with PHP?

    Best regards,

    ASchweti

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ASchweti...it's in an attachment; they filter them for viruses (or something) before posting them - it'll be there eventually...it is possible, as I think you'll see. I'd say reasonably robust, but others may differ about the thickness of that eis. I love PHP so, not prepared to argue against using that option.

    Cheers, adios
    ::: certified wild guess :::

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So it seems you speak german

    --

    Well in this case I suppose I will go with PHP. Regarding the Javascript solution(s) I would be very much dependant on what you Javascript gurus post me.

    Actually I just thought there is a little trigger I am missing in my code, especially because the dropdown and text field values stayed and only the values from the two selection boxs are gone. Since this does not seem to be the case, PHP will be fine for me.

    Thanks ASchweti

  7. #7
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ASchweti,

    I think your better off. Persistence is better left to a server-side solution as is validation. Adios is right, it can be done with javascript through cookies, frames or chopping up the search part of the url, but why do it that way when php already has the functionality built in.

    I'm curious though to see what you came up with Adios

  8. #8
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Germany
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi xDev,

    I'll post my solution as soon as I am done. It depends if on, if my client to pay the xtra hour...

    I am thinking of the following way. I save the array in a session variable. Then I will fill a second array with the entire list and compare the values of both arrays.

    Well, you'll see...

    Best regards,

    ASchweti


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
  •