By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Remove Selected Item from list

P: n/a
I have an issue that I am trying to solve. I have three select lists
(supposed to be preference 1, 2,3) and each of them have the same three
options. As soon as I select one of the choices from list1, i would
like to remove it from the options of list 2 and so on for list 3.

So effectively, List 2 has two choices and List3 only has one choice
that can be made.

Any pointers on how to accomplish this?

Oct 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
VK
<http://www.google.com/search?hl=en&q=select+list+remove+option+JavaScrip t>

Oct 19 '05 #2

P: n/a
Unfortunately, I really havent been able to get this going at all. I
havent found much help to proceed any further. Any pointers, please?

Oct 25 '05 #3

P: n/a
<rk******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have an issue that I am trying to solve. I have three select lists
(supposed to be preference 1, 2,3) and each of them have the same three
options. As soon as I select one of the choices from list1, i would
like to remove it from the options of list 2 and so on for list 3.

So effectively, List 2 has two choices and List3 only has one choice
that can be made.

Any pointers on how to accomplish this?


Is this what you're looking for? Watch for word-wrap.

<html>
<head>
<title>3selects.htm</title>
<script type="text/javascript">
function selects(n) {
var form = document.form1;
var indx = document.getElementById("s"+n).selectedIndex;
var valu = document.getElementById("s"+n).options[indx].value;
for (i=1; i<4; i++) {
if (i != n) {
for (j=0; j<document.getElementById("s"+i).length; j++) {
var what = document.getElementById("s"+i).options[j].value;
if (valu == what) {
document.getElementById("s"+i).options[j] = null;
}
}
}
}
}
</script>
</head>
<body>
<form action="" method="get" name="form1">
<select name="s1" id="s1" onchange="selects(1)" size="3">
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
<select name="s2" id="s2" onchange="selects(2)" size="3">
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
<select name="s3" id="s3" onchange="selects(3)" size="3">
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
</form>
</body>
</html>

If your task is to rank the preferences of three options then you might
want to consider just having two selections lists; one with the three
options and the other blank. As an option is selected it is added to
the second list in the order it was selected (and removed from the first
list). Then you process the second list for all values.

Oct 25 '05 #4

P: n/a
Thnaks a ton. That was precisely what I was looking for...... infact, I
was looking for soem pointers, but you provided the solution. Is there
a way to star a solution?

Thanks McKirahan

Oct 27 '05 #5

P: n/a
"Meister" <rk******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Thnaks a ton. That was precisely what I was looking for...... infact, I
was looking for soem pointers, but you provided the solution. Is there
a way to star a solution?

Thanks McKirahan


What do you mean by: "Is there a way to star a solution?"?

Are asking about the "two selections lists" approach?
Oct 28 '05 #6

P: n/a
In article <Dv********************@comcast.com>,
"McKirahan" <Ne**@McKirahan.com> wrote:
"Meister" <rk******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Thnaks a ton. That was precisely what I was looking for...... infact, I
was looking for soem pointers, but you provided the solution. Is there
a way to star a solution?

Thanks McKirahan


What do you mean by: "Is there a way to star a solution?"?

Are asking about the "two selections lists" approach?


I'm going out on a limb here, but I think he's asking if there is a way
to highlight a solution on Usenet. The answer, of course, is no.
Oct 28 '05 #7

P: n/a
"Mark Twain" <tw***@whitehouse.gov> wrote in message
news:1130504996.8872205f0eb5b2e0e763e7e041bc8757@t eranews...
In article <Dv********************@comcast.com>,
"McKirahan" <Ne**@McKirahan.com> wrote:
"Meister" <rk******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Thnaks a ton. That was precisely what I was looking for...... infact, I was looking for soem pointers, but you provided the solution. Is there
a way to star a solution?

Thanks McKirahan


What do you mean by: "Is there a way to star a solution?"?

Are asking about the "two selections lists" approach?


I'm going out on a limb here, but I think he's asking if there is a way
to highlight a solution on Usenet. The answer, of course, is no.


I thought that might be what's meant but here's the other approach....
<html>
<head>
<title>3rank.htm</title>
<script type="text/javascript">
var opti;
function rank(what) {
var form = document.form1;
if (what == 0) {
form.s1.options[0] = new Option("One", 1);
form.s1.options[1] = new Option("Two", 2);
form.s1.options[2] = new Option("Three", 3);
form.s2.options[2] = null;
form.s2.options[1] = null;
form.s2.options[0] = null;
opti = 0;
} else {
var indx = form.s1.selectedIndex;
if (indx < 0) return;
var text = form.s1.options[indx].text;
var valu = form.s1.options[indx].value;
form.s1.options[indx] = null;
form.s2.options[opti++] = new Option(text, valu);
}
}
</script>
<style type="text/css">
..sel1 { width:80px }
..sel2 { width:80px; background:#EFEFEF }
</style>
</head>
<body onload="rank(0)">
<form action="" method="get" name="form1">
<select name="s1" id="s1" size="3" class="sel1" onclick="rank(1)">
</select>
<select name="s2" id="s2" size="3" class="sel2" disabled>
</select>
<input type="button" value="Reset" onclick="rank(0)">
</form>
</body>
</html>
Oct 28 '05 #8

P: n/a
yeah i was looking to mark an answer as a solution

Nov 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.