View Full Version : Adding dependancies between select lists

07-25-2009, 08:31 PM
Hello guys,

I am using the javascript from:

I have added a third row of selection by adding into the <script>:

function getStateList(sel)
var countryCode = sel.options[sel.selectedIndex].value;
document.getElementById('dhtmlgoodies_state').options.length = 0; // Empty city select box
var index = ajax.length;
ajax[index] = new sack();

ajax[index].requestFile = 'getCities.php?countryCode='+countryCode; // Specifying which file to get
ajax[index].onCompletion = function(){ createState(index) }; // Specify function that will be executed after file has been found
ajax[index].runAJAX(); // Execute AJAX function

function createState(index)
var obj = document.getElementById('dhtmlgoodies_state');
eval(ajax[index].response); // Executing the response from Ajax as Javascript code

and into html

<td><h1>State:</h1> </td>
<td><select id="dhtmlgoodies_state" name="dhtmlgoodies_state" onchange="getCityList(this)">

Does anyone know how to add dependencies so that the second selection appears (graphically) after the first one is selected, and the third one after the second?

That would help me much because there is a slight bug with this script, now I added a row (when third selected, selecting back to the first makes second only empty...) and this would sort it + would look fancier obviously.

I found a post here about this effect: http://codingforums.com/showthread.php?t=172748
but since I am using a lot of variables in my lists (50), it would be a pain to use this technique.

Thanks a lot!