Connecting Tech Pros Worldwide Help | Site Map

Dropdown menus problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 11th, 2005, 11:15 PM
Ian Davies
Guest
 
Posts: n/a
Default Dropdown menus problem

Hello
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, or can direct me to a
suitable link?

Thanks
Ian



  #2  
Old November 12th, 2005, 12:15 AM
meltedown
Guest
 
Posts: n/a
Default Re: Dropdown menus problem

Ian Davies wrote:[color=blue]
> Hello
> 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, or can direct me to a
> suitable link?
>
> Thanks
> Ian
>
>[/color]
If I understand you correctly this is not a problem for php. You want
javascript. PHP only works when you open the page because it is a server
side language.
  #3  
Old November 21st, 2005, 11:05 PM
shawn
Guest
 
Posts: n/a
Default Re: Dropdown menus problem


"Ian Davies" <iandan.dav@virgin.net> wrote in message
news:0X9df.16209$Ua6.7984@newsfe6-win.ntli.net...[color=blue]
> Hello
> 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, or can direct me to a
> suitable link?
>
> Thanks
> Ian
>
>[/color]

There are two things you need to do and actually two different ways.

1. Do them all on client side using Javascript. add event handler for the
first select to handle onChange event.

2. Do it partly on client side and send it back to server on the event
"onChange". and re-build the second select options with values based on what
is sent back from options of the first select.

Shwn


  #4  
Old November 21st, 2005, 11:05 PM
sCOTT
Guest
 
Posts: n/a
Default Re: Dropdown menus problem

Ian Davies wrote:[color=blue]
> Hello
> 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, or can direct me to a
> suitable link?
>
> Thanks
> Ian
>
>[/color]
It would be possible to do this with PHP by submitting the page back to
itself and load the second menu depending on your $_POST value.
The downside is that you would be reloading the complete page each time
the first drop down menu is selected. If you have a fast page it may not
even be a problem.
  #5  
Old November 21st, 2005, 11:06 PM
Meião
Guest
 
Posts: n/a
Default Re: Dropdown menus problem

Take a look at PEAR's HTML/QuickForm
they have something that looks like this.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.