Forum Moderators: open
1. Guns
2. Butter
Contents of Guns:
Value="1" Name="red widgets"
Value="2" Name="blue widgets"
Value="3" Name="green widgets"
Contents of Butter;
Value="1" Name="green ham"
Value="2" Name="blue turkey"
Value="3" Name="red chicken"
Is there a way to make the second option in butter, "blue turkey", disappear when someone selects "blue widgets" from gun drop down?
(As everyone knows, blue widgets doesn't go with blue turkey :) )
If so, what happens if someone selects "blue turkey" first, then later chooses "blue widgets"...will it handle that properly.
I'm glad you warned me about blue turkey vis-a-vis blue widgets. I could have made a catastrophic faux pas.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
<script type="text/javascript">
function syncSels(orig,targ_sel){
var sels=document.getElementsByTagName('select'); // places all selects in sels[] array
var indx=orig.selectedIndex; // gets index of the selected option in the initiating select
if(sels[targ_sel].childNodes[0].nodeType!=1) indx=indx+1; // adjust for browsers that insert a comment node
sels[targ_sel].removeChild(sels[targ_sel].childNodes[indx]); // remove target
}
</script>
</head>
<body>
<form action="">
<p>
<select onchange="syncSels(this,1);"> <!-- passes this select and the target select's sels[] index number -->
<option value="1">Remington</option>
<option value="2">Winchester</option>
<option value="3">Colt</option>
</select>
</p>
<p>
<select onchange="syncSels(this,0);">
<option value="1">Land O Lakes</option>
<option value="2">Tillamook</option>
<option value="3">Lucerne</option>
</select>
</p>
</form>
</body>
</html>
Note: I've only tested this on Linux, with Firefox and Konqueror.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type="text/css">
</style>
<script type="text/javascript">
function syncSels(orig,targ_sel){
var sels=document.getElementsByTagName('select'); // places all selects in sels[] array
var indx=orig.selectedIndex; // gets index of the selected option in the initiating select
sels[targ_sel].options[indx].parentNode.removeChild(sels[targ_sel].options[indx]);
}
</script>
</head>
<body>
<form action="">
<p>
<select onchange="syncSels(this,1);"> <!-- passes this select and the target select's sels[] index number -->
<option value="0">Remington</option>
<option value="1">Winchester</option>
<option value="2">Colt</option>
</select>
</p>
<p>
<select onchange="syncSels(this,0);">
<option value="0">Land O Lakes</option>
<option value="1">Tillamook</option>
<option value="2">Lucerne</option>
</select>
</p>
</form>
</body>
</html>