Automatically populate a pull down list...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick

    Automatically populate a pull down list...

    What I want to do is have 2 pull down lists, for example a state pull
    down list and a city pull down list. What I would like to have done is
    when you select a state from the state pull down list then the city
    pull down list will populate with all the cities from that selected
    state. I know that is a lot of data but that is just an example. Or
    something like when you are looking up cars online they have a make
    pull down list and a model pull down list, and when you select the make
    it will populate the model pull down list with all the models from that
    make. Thank you.

  • Peter van Schie

    #2
    Re: Automatically populate a pull down list...

    Nick wrote:[color=blue]
    > What I want to do is have 2 pull down lists, for example a state pull
    > down list and a city pull down list. What I would like to have done is
    > when you select a state from the state pull down list then the city
    > pull down list will populate with all the cities from that selected
    > state. I know that is a lot of data but that is just an example. Or
    > something like when you are looking up cars online they have a make
    > pull down list and a model pull down list, and when you select the make
    > it will populate the model pull down list with all the models from that
    > make. Thank you.
    >[/color]

    Hi Nick,

    You basically have two options:

    1. Use client-side Javascript: load the data from both lists into
    javascript arrays and write an onclick handler for the first selectbox,
    to set the contents of the second selectbox.
    You could check out

    for example. You can use that component which works like I described.

    2. Use AJAX to allow communication with the server when you click an
    item in the first selectbox. You don't need to preload all data
    client-side like that.
    If you want to know more about this technique, read my tutorial at:


    HTH.

    --

    Comment

    • Peter Fox

      #3
      Flying screens (was Automatically populate a pull down list...)

      Following on from Peter van Schie's message. . .[color=blue]
      >You basically have two options:[/color]
      Three!

      A single list with all options in the form state,city (or city,state)
      sorted on the first item. No JS or anything else required.


      Four!

      Of course PHP sends a whole page and then shuts down so isn't
      interactive to the level you want . . .
      .. . . But there *is* as way using what I call a flying screen:
      The principle is that your page _opens a new window_ containing a form
      filled with /the appropriate/ list which then returns the selection to
      the session and closes itself.

      In your particular case I wouldn't use it as the main window doesn't
      update, but it can be handy if you have say a form with the possibility
      of wanting to edit the details of some of the items in it. eg:

      Team leader [Jim Smith v] [>details]

      (drop down and button) where the button brings up details of Jim Smith
      in a separate window, perhaps with the possibility of 'doing things',
      This means that the main flow is not obscured.

      or
      Project [Cold Fusion v] [>projects]
      where the button allows you to edit the list of projects, perhaps going
      off into details about them in another window.

      Finally it _is_ possible to get the value picked in a flying window back
      to the main screen 'in real time'.
      Project name : Cold Fusion [>Change]
      where the Change button leads to a screen that allows you to maintain
      and select a project, This requires clever javascript passing the
      document elements between documents. On closing the flying screen the
      form will now be updated to perhaps
      Project name : Indian Rope Trick [>Change]

      * The advantage of this technique is the flying window is just a side
      branch to the main flow of the form which only needs to be used on
      occasion but is there where you want it when you want it rather than
      having to traipse round the system looking for a maintenance screen.

      * The disadvantage is that it is rather hairy.

      I've written an article on the subject and have packaged code but I
      can't find the article at present and the code would need some hacking
      to integrate with the way you write screens ('cos I have a weird home
      grown method which is great for quick building but NBG for glueing to
      non-weird code models.)

      --
      PETER FOX Not the same since the statuette business went bust
      peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
      2 Tees Close, Witham, Essex.
      Gravity beer in Essex <http://www.eminent.dem on.co.uk>

      Comment

      Working...