SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast nickweavers's Avatar
    Join Date
    Feb 2004
    Location
    Hampshire, UK
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cascaded drop downs and persistence ?

    Can anyone help me with the following scenario?

    I have a web page that includes three selection lists. These are built using PHP to get the option calues for a database. The first is just a list of Categories and is easy. The second is a list of regions and so is also easy. The third, however, is a list of Counties that lie within the region chosen by the user from the Region selection list and so cannot be built before that choice is made.

    After all three search fields are completed, the page calls itself via the forms action property and detects via the submit button having a value that it now has do do the query and display the results. It also has to paginate these, allowing the user to page-forward and page-back through the results.

    At all times the search selection drops downs are visible and should still be set to the values that caused the selection of the data currently being presented, but should allow new choices to be selected and a new query to be performed.

    I managed to find some javascript that would build my Counties select list dynamically as soon as an onChange event was detected on the Regions selection, but this doesn't cope with holding it's "state" across pages.

    The problem essentially seems to be caused by me trying to use a combination of server and client scripting that isn't sharing state information. I think if I could use the onChange event property on the Region selection to redirect me back to myself with the selected region set in $_POST['Region'] and some way of detecting how I got here, I could build the Counties selection and hold it through subsequent pages.

    Can anyone help? I may not have explained my problem very well so please feel free to ask for clarification.

    Best regards,
    Nick.

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Nick,

    The only way you can maintain 'state' with javascript is to use cookies. So...before submitting, write the values to a cookie and then read them after writing, but before displaying, the new page. (www.htmlgoodies.com used to have an easy to understand tutorial on cookie creation)

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •