PDA

View Full Version : Changing dropdown



hello1215
Sep 6th, 2002, 04:33 PM
I want to be able to set a drop down based on what was selected in a previous drop down. For example, if in the first drop down the user selected Blue, I want the second drop down to automatically set to Sky. Does anyone know of a way to do this.

Thanks.

beetle
Sep 6th, 2002, 04:43 PM
I had some functions in my code library that can help you out. I custom made the doSelect() function for this example, and thanks to jkd for the getNode() function.
<script>
function setSel(objName, selVal) {
var selObj = getNode(objName);
for (var i=0; i<selObj.length; i++)
if (selObj.options[i].value == selVal)
selObj.selectedIndex = i;
}

function getNode(id) {
return (typeof document.layers != 'undefined') ? document.layers[id] : (document.getElementById || document.all)(id);
}

function doSelect(val) {
var temp = (val == 'blue') ? 'sky' : (val == 'green') ? 'grass' : (val == 'brown') ? 'earth' : 'fire';
setSel('elements',temp);
}
</script>

<select id="colors" onChange="doSelect(this.options[this.selectedIndex].value">
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="brown">Brown</option>
<option value="red">Red</option>
</select>

<select id="elements">
<option value="sky">Sky</option>
<option value="grass">Grass</option>
<option value="fire">Fire</option>
<option value="earth">Earth</option>
</select>

requestcode
Sep 6th, 2002, 05:39 PM
There are also some double combo scripts in the Free Scripts section:
http://www.wsabstract.com/script/cutindex16.shtml