Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Location
    on earth
    Posts
    183
    Thanks
    49
    Thanked 2 Times in 2 Posts

    Adding dependancies between select lists

    Hello guys,

    I am using the javascript from:
    http://www.dhtmlgoodies.com/index.ht...chained_select

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

    Code:
    function getStateList(sel)
    {
    	var countryCode = sel.options[sel.selectedIndex].value;
    	document.getElementById('dhtmlgoodies_state').options.length = 0;	// Empty city select box
    	if(countryCode.length>0){
    		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
    Code:
    <tr>
    		<td><h1>State:</h1> </td>
    		<td><select id="dhtmlgoodies_state" name="dhtmlgoodies_state" onchange="getCityList(this)">
    		</select></td>
    	</tr>
    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!
    Mik
    Last edited by mikacruz; 07-25-2009 at 07:44 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •