469,922 Members | 2,141 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,922 developers. It's quick & easy.

php/dynamic form problem

Hi, I have a page with 2 drop-down menus. The task is, when you select
1 menu, your selection then changes the options available in the
other. This data happens to be drawn from a mysql database, so I
wouldn't think that it could be done purely in Javascript, but rather
a combination of PHP generating some JS code. Thing is, I don't even
see how to change a set of menu options with JavaScript, only names
and values of individual fields.

Any hints and links to tutorials where the menu-changing part is
explained would be appreciated.

Thanks.

--
Stephan

Mar 17 '07 #1
3 1899
dr**********@gmail.com wrote:
Hi, I have a page with 2 drop-down menus. The task is, when you select
1 menu, your selection then changes the options available in the
other. This data happens to be drawn from a mysql database, so I
wouldn't think that it could be done purely in Javascript, but rather
a combination of PHP generating some JS code. Thing is, I don't even
see how to change a set of menu options with JavaScript, only names
and values of individual fields.

Any hints and links to tutorials where the menu-changing part is
explained would be appreciated.
I think you just run a tiny script from the <optiononmouseclick which
reloads the form, then when the form reloads, php sees the option value
has been set & formats the second option list.
Mar 17 '07 #2
Paul Furman wrote:
dr**********@gmail.com wrote:
>Hi, I have a page with 2 drop-down menus. The task is, when you select
1 menu, your selection then changes the options available in the
other. This data happens to be drawn from a mysql database, so I
wouldn't think that it could be done purely in Javascript, but rather
a combination of PHP generating some JS code. Thing is, I don't even
see how to change a set of menu options with JavaScript, only names
and values of individual fields.

Any hints and links to tutorials where the menu-changing part is
explained would be appreciated.

I think you just run a tiny script from the <optiononmouseclick which
reloads the form, then when the form reloads, php sees the option value
has been set & formats the second option list.
Its generally refered to as a cascaded select. The easiest way to acheive
the result is to generate javascript directly from your PHP code, or use an
ajax function to populate the second select. Regardless you'd be better
asking about this on a Javascript list.

Having said that, I much prefer the the old Mozilla behaviour of having
nested menus defined by optgroups but all borwsers now just use that as a
series of headers in what is still a single list. To implement the same
behaviour (i.e. all options in a single widget but nested) check out PHP
layers menu.

HTH

C.
Mar 17 '07 #3
Hello,

on 03/17/2007 09:07 AM dr**********@gmail.com said the following:
Hi, I have a page with 2 drop-down menus. The task is, when you select
1 menu, your selection then changes the options available in the
other. This data happens to be drawn from a mysql database, so I
wouldn't think that it could be done purely in Javascript, but rather
a combination of PHP generating some JS code. Thing is, I don't even
see how to change a set of menu options with JavaScript, only names
and values of individual fields.

Any hints and links to tutorials where the menu-changing part is
explained would be appreciated.
This is a frequently asked need, for which there are ready to use
components for that purpose.

I use this forms generation class that comes with a plug-in that can do
exactly what you ask: link two or more selected inputs in such way when
the value of one changes, the options of the following are switched.

There is a variant of that plug-in that picks new groups of options from
a MySQL database using AJAX requests to avoid page reloading.

The class and the plug-ins may be found here:
http://www.phpclasses.org/formsgeneration

Here you can see an example of the plug-in in action:
http://www.meta-language.net/forms-e..._linked_select

Here you can watch a tutorial video about this plug-in:
http://www.phpclasses.org/browse/vid...ed-select.html

--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Mar 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Will | last post: by
6 posts views Thread by MikeY | last post: by
reply views Thread by Venus | last post: by
3 posts views Thread by Tyler Carver | last post: by
7 posts views Thread by Abraham Luna | last post: by
reply views Thread by Scott Roberts | last post: by
reply views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.