Page 1 of 1

double combobox

Posted: Thu Jan 11, 2007 8:51 am
by vamsi_j
Hi i need a double combobox which needs the data to be fetched from the database dynamically.


database details there are two fields in the database name and email address

name email

Vamsi vamsi@vamsi.com

Vamsi krishna@vamsi.com

Krishna xyz@xyz.com

Krishna xyz@xyz.com

i need to fill the first combobox only with the names Vamsi and Krishna

If i select the name as Vamsi i need to get the two email address corresponding to Vamsi.

I was successful in populating one combobox.I failed in selections. Any sort of code help is appreciated.

Posted: Thu Jan 11, 2007 8:58 am
by impulse()
Firstly, I'd grab the names and e-mails from the database and store them in an array.
Secondly, generate the combo box in a loop that loops through as many times as there are items in the array using:

Code: Select all

value = '$yourArray[$i]'
for the values of each combo option.

Posted: Thu Jan 11, 2007 1:59 pm
by volka
you're looking for "chained select".
There are a lot of hits on google for that search term.

Posted: Fri Jan 12, 2007 12:35 pm
by CoderGoblin
On this site I have created a couple of topics on this...
Javascript and Dynamic Select Boxes
Dynamic/Chained Selects using Ajax with Prototype

At some point soon I will probably do another example using the JQuery javascript library.

PHP only

Posted: Tue May 01, 2007 10:13 pm
by desb01
Is it possible to do it without using javascript (using only php).

I created two combobox filling with php and mySql.

But I need the second combobox to show choice based on the selection of the first combobox.

How do I do that ?

Thank you in advance.

Posted: Wed May 02, 2007 3:12 am
by CoderGoblin
If you do not have javascript (or don't want to use it) your only alternative is to submit the form when the user selects the first item. This is normally performed with a submit button next to the first select item.
Dynamic/Chained Selects using Ajax with Prototype has an example which works even with javascript switched off.