Connecting Tech Pros Worldwide Forums | Help | Site Map

dropdown menu problem

Ian Davies
Guest
 
Posts: n/a
#1: Nov 23 '05
Hello
Ive been informed that I need to do the following in javascript.
I have two drop down menus in my php script. The items displayed in the
second is dependent on which item is choosen from the first i.e. the choosen
item from the first filters the items in the second

first dropdown menu
sub no sub
1 science >>>>>>>>> if this is selected
2 maths
3 something else


second dropdown menu
TopicNo sub no TopicDesc
1 1 Science Topic1 >>>>>>>>>>>>>>>> displayed
2 2 Maths topic 1
3 3 Something else Topic1
4 1 Science topic 2>>>>>>>>>>>>>>>> displayed
5 2 Maths Topic 2
6 3 Something else topic 2

all others not displayed

The problem is this only works once when I open the page (with the default
values).
I would like to get the second dropdown box to update as soon as an Item is
selected from the first. I have searched the net but cannot find anything.
It seems that this is something that is not commonly done. The data for
populating the lists comes from a mysql database.

Does anyone know of a script to do this with php and/or Java, or can direct
me to a
suitable link?

Thanks
Ian




RobG
Guest
 
Posts: n/a
#2: Nov 23 '05

re: dropdown menu problem


Ian Davies wrote:[color=blue]
> Hello
> Ive been informed that I need to do the following in javascript.
> I have two drop down menus in my php script. The items displayed in the
> second is dependent on which item is choosen from the first i.e. the choosen
> item from the first filters the items in the second[/color]

[...][color=blue]
>
> The problem is this only works once when I open the page (with the default
> values).[/color]

Without showning what you have attempted no one can tell you where it is
going wrong.

[color=blue]
> I would like to get the second dropdown box to update as soon as an Item is
> selected from the first. I have searched the net but cannot find anything.[/color]

There are thousands upon thousands of such scripts... Google 'dynamic
menu list' or 'dynamic option list'.

[color=blue]
> It seems that this is something that is not commonly done.[/color]

It is very common and can be done purely in CSS:

<URL:http://www.howtocreate.co.uk/tutorials/testMenu.html>


or in javascript:

<URL:http://www.litotes.demon.co.uk/example_scripts/>




--
Rob
Matt Kruse
Guest
 
Posts: n/a
#3: Nov 23 '05

re: dropdown menu problem


Ian Davies wrote:[color=blue]
> I would like to get the second dropdown box to update as soon as an
> Item is selected from the first.
> I have searched the net but cannot
> find anything. It seems that this is something that is not commonly
> done.[/color]

You may not searched on the right keywords, because solutions for this are
all over the web, and it is a quite common thing to be done.
For example,
http://www.JavascriptToolbox.com/dynamicoptionlist/
[color=blue]
> The problem is this only works once when I open the page (with the
> default values).[/color]

This leads me to believe that you're firing a sql query to get the values
for the second list for only the value that is in the first list.
You have a couple of options:

1) You can fire the query every time the first box changes and populate the
second box. This will either require an ajax-like technique, or reloading
the page.

2) You can query for all possibilities when building the page, and code all
possible variations into pure javascript which will populate the second box
immediately on change of the first. This is the technique used in my url
above.

Which solution you pick depends a lot on your environment, browser support,
degradation requirements, and experience.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Closed Thread