Current location: Hot Scripts Forums » Programming Languages » PHP » how to create two dropdown menu linking each other?

how to create two dropdown menu linking each other?

  #1 (permalink)  
Newbie Coder
Join Date: Nov 2010
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
how to create two dropdown menu linking each other?

Hi guys, i have to create a drop-down menu for database data, when i select one data from that then next drop-down menu has to create automatically with related data of the 1st selection.
could anyone please give me some help to do this?

NB: i have 3 tables student(sid, sname), course (cid, cname) , take (sid, cid) so if i select one of the cid then another drop down list has to create automatically with sid who is taking the cid .
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old's Avatar
Newbie Coder
Join Date: Nov 2010
Location: Setúbal, near Lisbon
Posts: 96
Thanks: 3
Thanked 7 Times in 7 Posts
Sometime ago I've built a little something similar to what you need.
I needed to have a product classification under a family and then under a sub-family.
This is how I got it done. It should refresh the second combobox automatically as you chage the first one.

PHP Code:

="    select       cliente_nr
                            , familia_name
                            , codigo_familia_pk  ( this is the primary key )
                    from stocks_produtos_familias"
# determines the master combo
    <select name='prod_familia' onchange='javascript: document.form.submit();'>
        <option value='0'>&nbsp</option>"
while (
$familia=mysql_fetch_row($fam)) {
# if this the selected family
if ($familia[2]==$_POST[prod_familia])     {
# sets up the slave combo
$string_pesquisa="    select     cliente_nr, 
                                    sub_familia_pk (this is the sub family primary key)
                            from stocks_produtos_subfamilias
                            and codigo_familia_master=
        if (
mysql_num_rows($sub_fam)>0)    {
            <select name='prod_subfamilia' class='preto' style='background:white; padding:3px; border: thin solid grey;' 
                onchange='javascript: document.alt_produto.submit();'>
                <option value='0'>&nbsp</option>"
# builds up the slave combo
while ($sub_familia=mysql_fetch_row($sub_fam)) {
                if (
$sub_familia[3]==$ficha_produto[4])     {$sel_2="selected='selected'";}
                else                                         {
$combo_subfamilia.="<option value='$sub_familia[3]$sel_2>$sub_familia[2]</option>";
# sif this is not the selected family
else {$sel=NULL;}    
$combo_familia.="<option value='$familia[2]$sel>$familia[1]</option>";


<form name='alt_produto' method='post' action='
$combo_familia   <br/>


On the same basis you can build a similar to suit you.
Have fun!

Last edited by; 11-14-10 at 07:14 PM.
Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Create dropdown menu from comma separated list of numbers maya77 PHP 22 03-20-11 11:35 AM
Superfish jquery menu problems with modification transcend2005 CSS 2 03-25-09 01:30 AM
css problem with the scroll bar CSS 0 11-04-08 05:34 PM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM

All times are GMT -5. The time now is 02:45 PM.
vBulletin® Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.