By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,738 Members | 1,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,738 IT Pros & Developers. It's quick & easy.

dependent select menus

P: n/a
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 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a


On 23 Jan, 23:47, "abracad_1...@yahoo.com" <abracad_1...@yahoo.com>
wrote:
Is there another, better way that can dynamically change the initial page?
AJAX

Jan 24 '07 #2

P: n/a
ab**********@yahoo.com 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/
Jan 24 '07 #3

P: n/a

<ab**********@yahoo.comschreef in bericht
news:11**********************@l53g2000cwa.googlegr oups.com...
>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
Jan 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.