Chained Select (DHTMLSuite.chainedSelect)

DHTML Suite - article index



To use this script, include the contextMenu widget with lines like this:

<table cellpadding="5" cellspacing="5">
         <select id="country">
         <option>select a country</option>
         <option value="turkey">Turkey</option>
         <option value="denmark">Denmark</option>
         <option value="norway">Norway</option>
         <select id="city"></select>
         <select id="university"></select>

<script type="text/javascript">
chainedSelects = new DHTMLSuite.chainedSelect(); // Creating object of class DHTMLSuite.chainedSelects

Here, we have three select boxes. the addChain method connects one select box with another. The "country" select box is connected with the "city" box, and the "city" box has been connected with the "university" box.

When someone chooses a country inside the country select box, a call will be made to getCities.php which will list availabale cities inside that country in the "city" select box. The same applies to the "city" select box.

This is how the getCities.php file look like in the demo:

header("Content-Type: text/html;charset=iso-8859-1");

switch ( $_GET['dg_key']) {
   case "turkey" : echo "Ankara;06 | Istanbul;34 | Antalya;07"; break;
   case "denmark": echo "Aalborg;11 | Copenhagen;22 | Odense;33"; break;
   case "norway" : echo "Bergen;44 | Oslo;55 | Stavanger;66"; break;
   default : echo "no item";



You will typically use a SQL query in this file in order to filter out cities.

LudoJS framework
Go to

About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2020