dependent select menus

Discussion in 'HTML' started by abracad_1999@yahoo.com, Jan 23, 2007.

  1. Guest

    I would like to create a form in which a 2nd select box appears
    depending on the value selected in the 1st select box. The values of
    the 2nd select box will come from a database.

    My question is how to create this in php? One way is to re-load the
    page depending on what's chosen in the first box, or alternatively to
    use frames or an iframe?

    Is there another, better way that can dynamically change the initial
    page?
    , Jan 23, 2007
    #1
    1. Advertising

  2. Myron Turner Guest

    wrote:
    > I would like to create a form in which a 2nd select box appears
    > depending on the value selected in the 1st select box. The values of
    > the 2nd select box will come from a database.
    >
    > My question is how to create this in php? One way is to re-load the
    > page depending on what's chosen in the first box, or alternatively to
    > use frames or an iframe?
    >
    > Is there another, better way that can dynamically change the initial
    > page?
    >

    The way to do this without reloading the page is with Ajax and
    javascript. When the user makes the first selection, the page makes a
    call to the server which sends back the 2nd set of selections, which can
    then be plugged into the second selection box.

    The script on the server can be written in PHP. It can send back a
    javascript array with the new set of selection values. I would suggest
    creating an empty javascript array in the original page and then
    populating it with the results returned from the server.

    --

    _____________________
    Myron Turner
    http://www.room535.org
    http://www.bstatzero.org
    http://www.mturner.org/XML_PullParser/
    Myron Turner, Jan 24, 2007
    #2
    1. Advertising

  3. Michael Guest

    <> schreef in bericht
    news:...
    >I would like to create a form in which a 2nd select box appears
    > depending on the value selected in the 1st select box. The values of
    > the 2nd select box will come from a database.
    >
    > My question is how to create this in php? One way is to re-load the
    > page depending on what's chosen in the first box, or alternatively to
    > use frames or an iframe?
    >
    > Is there another, better way that can dynamically change the initial
    > page?


    You could use Javascript to either
    a) hide all select boxes except the one corresponding to the choice (by
    editing the display property), and have the PHP script generate a SELECT for
    each possible choice with "display: none" set by default
    b) have the PHP generate a Javascript which will clear the second box and
    re-fill it with the appropriate entries onChange of the first select

    I think you need Javascript one way or another, if you want to get around
    reloading the page (whether it be the main page or an (i)frame).

    Regards

    Michael
    Michael, Jan 24, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.west.cox.net

    Select menus above flyout menus? help?

    news.west.cox.net, Dec 8, 2004, in forum: HTML
    Replies:
    8
    Views:
    779
  2. dbuchanan
    Replies:
    6
    Views:
    2,824
    Steven Cheng [MSFT]
    Jun 11, 2008
  3. puzzlecracker
    Replies:
    1
    Views:
    507
    James Kanze
    Aug 7, 2008
  4. palmiere
    Replies:
    1
    Views:
    384
    Erwin Moller
    Feb 9, 2004
  5. Alexander Ryck

    2 dyn. select-menus in 1 Form

    Alexander Ryck, Mar 6, 2004, in forum: Javascript
    Replies:
    3
    Views:
    108
    Alexander Ryck
    Mar 7, 2004
Loading...

Share This Page