View Full Version : Changing dropdown

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.


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.
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';

<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 id="elements">
<option value="sky">Sky</option>
<option value="grass">Grass</option>
<option value="fire">Fire</option>
<option value="earth">Earth</option>

Sep 6th, 2002, 05:39 PM
There are also some double combo scripts in the Free Scripts section: