"Simon Templar" <po********@gmx.co.uk> wrote in message
news:2u*************@uni-berlin.de...
This code works fine. The only problem appears when the user changes their
selection. The second listbox does not show the hidden option back. I will
try to improve that.
Thanks!
[snip]
Try this; watch for word-wrap.
<html>
<head>
<title>selnodups.htm</title>
<script type="text/javascript">
function selects(what) {
var form = document.forms[0];
var opts = new Array;
opts[0] = "";
opts[1] = "Chicago";
opts[2] = "New York";
if (what == 0) {
form.Sel1.options.length = 0;
}
form.Sel2.options.length = 0;
for (var i=0; i<opts.length; i++) {
if (what == 0) {
form.Sel1.options[i] = new Option(opts[i], i);
}
form.Sel2.options[i] = new Option(opts[i], i);
}
}
function noDuplicate() {
var form = document.forms[0];
selects(1);
var valu = form.Sel1.options[form.Sel1.selectedIndex].value;
form.Sel2.options[valu] = null;
}
</script>
</head>
<body onload="selects(0)">
<form>
<b>From :</b>
<select name="Sel1" onchange="noDuplicate()">
</select>
<b>To :</b>
<select name="Sel2">
</select>
</form>
</body>
</html>
This link may help:
http://www.quirksmode.org/js/options.html