Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

How to create a dependent drop down box ?

Question posted by: pugalenthi (Member) on May 8th, 2008 10:17 AM
I have created a dropdown box which is populated by data from the mssql server database connected using ODBC. Now i need to populate another dropdown box which will also be from the database but will be based on the value selected in the already created dropdown box. The following is how i have created a dropdown box,

Expand|Select|Wrap|Line Numbers
  1. $sql_visitor= "SELECT DISTINCT Contained FROM IAIS_Ubisense";
  2.    $rs3=odbc_exec($connection,$sql_visitor); 
  3.     echo "<select name=\"name\">"; 
  4.     echo "<option size =30 selected>Select</option>";
  5.     if(odbc_num_rows($rs3)) 
  6.     { 
  7.     while(odbc_fetch_row($rs3)) 
  8.     { 
  9.     $visitor=odbc_result($rs3,"Contained");
  10.     echo "<option>$visitor</option>"; 
  11.     }  
  12.     } 
  13.     else 
  14.     {
  15.     echo "<option>No Names Present</option>";  
  16.     }


now i need to get the value from the selection made in the above dropdown box, so that i can use it to create a dependent dropdown box. Please help me in this regard.
ronverdonk's Avatar
ronverdonk
Moderator
4,139 Posts
May 8th, 2008
02:14 PM
#2

Re: How to create a dependent drop down box ?
You'll have to use a combination of PHP and JavaScript (Ajax) to accomplish this.
Instead of explaining the whole process, it is better to point you to some tutorials on the subject of populating consecutive drop down boxes dynamically from MySQL using Ajax. These are

Ajax Cascading Drop-down Example
AJAX chained select

Ronald

Reply
pugalenthi's Avatar
pugalenthi
Member
44 Posts
May 9th, 2008
10:58 AM
#3

Re: How to create a dependent drop down box ?
Quote:
You'll have to use a combination of PHP and JavaScript (Ajax) to accomplish this.
Instead of explaining the whole process, it is better to point you to some tutorials on the subject of populating consecutive drop down boxes dynamically from MySQL using Ajax. These are

Ajax Cascading Drop-down Example
AJAX chained select

Ronald


Is it possible to accomplish the cascading drop down list by reloading the webpage. If yes, how ?

Reply
rpnew's Avatar
rpnew
Familiar Sight
174 Posts
May 9th, 2008
11:34 AM
#4

Re: How to create a dependent drop down box ?
Quote:
Is it possible to accomplish the cascading drop down list by reloading the webpage. If yes, how ?


Hi,
It is possible. When you are changing the content of first drop down box submit the page with its value to same page. Then check for that value, load it in first box and load data accordingly in second box.

Regards,
RP

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,873 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top PHP Forum Contributors