/** * Copyright (c)2005-2007 Matt Kruse (javascripttoolbox.com) * * Dual licensed under the MIT and GPL licenses. * This basically means you can use this code however you want for * free, but don't claim to have written it yourself! * Donations always accepted: http://www.JavascriptToolbox.com/donate/ * * Please do not link to the .js files on javascripttoolbox.com from * your site. Copy the files locally to your server instead. * */ // Global objects to keep track of DynamicOptionList objects created on the page var dynamicOptionListCount=0; var dynamicOptionListObjects = new Array(); // Init call to setup lists after page load. One call to this function sets up all lists. function initDynamicOptionLists() { // init each DynamicOptionList object for (var i=0; i 0) { // Process arguments and add dependency groups for (var i=0; i this.numberOfOptions[this.currentNodeDepth]) { this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length; } if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) { this.longestString[this.currentNodeDepth] = text; } } this.currentNode = null; this.currentNodeDepth = 0; } // Add sub-options to the currently-selected node, specifying separate text and values for each option function DOL_addOptionsTextValue() { if (this.currentNode==null) { this.currentNode = this; } if (this.currentNode["options"] == null) { this.currentNode["options"] = new Array(); } for (var i=0; i this.numberOfOptions[this.currentNodeDepth]) { this.numberOfOptions[this.currentNodeDepth] = this.currentNode.options.length; } if (typeof(this.longestString[this.currentNodeDepth])=="undefined" || (text.length > this.longestString[this.currentNodeDepth].length)) { this.longestString[this.currentNodeDepth] = text; } } this.currentNode = null; this.currentNodeDepth = 0; } // Find the first dependent list of a select box // If it's the last list in a chain, return null because there are no children function DOL_child(obj) { var listIndex = this.fieldListIndexes[obj.name]; var index = this.fieldIndexes[obj.name]; if (index < (this.fieldNames[listIndex].length-1)) { return this.form[this.fieldNames[listIndex][index+1]]; } return null; } // Set the options which should be selected by default for a certain value in the parent function DOL_setDefaultOptions() { if (this.currentNode==null) { this.currentNode = this; } for (var i=0; i objects for Netscape4, since it refuses to grow or shrink select boxes for new options function DOL_printOptions(name) { // Only need to write out "dummy" options for Netscape4 if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) <= 4)){ var index = this.fieldIndexes[name]; var ret = ""; if (typeof(this.numberOfOptions[index])!="undefined") { for (var i=0; i0 && obj.selectedIndex>=0) { var o = obj.options[obj.selectedIndex]; this.populateChild(o.DOLOption,child,usePreselected); this.selectChildOptions(child,usePreselected); } } else if (obj.type == "select-multiple") { // For each selected value in the parent, find the options to fill in for this list // Loop through the child list and keep track of options that are currently selected var currentlySelectedOptions = new Array(); if (!usePreselected) { for (var i=0; i0) { obj.options[0].selected = true; } else if (!atLeastOneSelected && obj.type=="select-one") { obj.selectedIndex = -1; } }