473,395 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dependent listboxes

I need the following functionality: With 2 listboxes populated from a
database with the SAME data, I need any of the listboxes to stop displaying
the option when selected at the other listbox. Eg: data records are A and B,
and initially are available in both listboxes, but once the user selects A
in the first listbox, the second one should only display B.

Any reference?
Jul 23 '05 #1
3 1692
"Simon Templar" <po********@gmx.co.uk> wrote in message
news:2u*************@uni-berlin.de...
I need the following functionality: With 2 listboxes populated from a
database with the SAME data, I need any of the listboxes to stop displaying the option when selected at the other listbox. Eg: data records are A and B, and initially are available in both listboxes, but once the user selects A
in the first listbox, the second one should only display B.

Any reference?


Will this help? Watch for word-wrap.

<html>
<head>
<title>selnodup.htm</title>
<script type="text/javascript">
function noDuplicate() {
var form = document.forms[0];
var valu = form.Sel1.options[form.Sel1.selectedIndex].value;
form.Sel2.options[valu] = null;
}
</script>
</head>
<body>
<form>
<b>From :</b>
<select name="Sel1" onchange="noDuplicate()">
<option value="">
<option value="1">Chicago
<option value="2">New York
</select>
&nbsp; &nbsp;
<b>To :</b>
<select name="Sel2">
<option value="">
<option value="1">Chicago
<option value="2">New York
</select>
</form>
</body>
</html>

Jul 23 '05 #2
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!

"McKirahan" <Ne**@McKirahan.com> escribió en el mensaje
news:qMSgd.335583$3l3.245825@attbi_s03...
"Simon Templar" <po********@gmx.co.uk> wrote in message
news:2u*************@uni-berlin.de...
I need the following functionality: With 2 listboxes populated from a
database with the SAME data, I need any of the listboxes to stop displaying
the option when selected at the other listbox. Eg: data records are A and B,
and initially are available in both listboxes, but once the user selects

A in the first listbox, the second one should only display B.

Any reference?


Will this help? Watch for word-wrap.

<html>
<head>
<title>selnodup.htm</title>
<script type="text/javascript">
function noDuplicate() {
var form = document.forms[0];
var valu = form.Sel1.options[form.Sel1.selectedIndex].value;
form.Sel2.options[valu] = null;
}
</script>
</head>
<body>
<form>
<b>From :</b>
<select name="Sel1" onchange="noDuplicate()">
<option value="">
<option value="1">Chicago
<option value="2">New York
</select>
&nbsp; &nbsp;
<b>To :</b>
<select name="Sel2">
<option value="">
<option value="1">Chicago
<option value="2">New York
</select>
</form>
</body>
</html>

Jul 23 '05 #3
"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>
&nbsp; &nbsp;
<b>To :</b>
<select name="Sel2">
</select>
</form>
</body>
</html>

This link may help: http://www.quirksmode.org/js/options.html
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
1
by: Ryan Ternier | last post by:
I have two listboxes, and allow users to move items between them via the following function: function SwitchList(fbox, tbox){ var arrFbox = new Array(); var arrTbox = new Array(); var...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
2
by: salad | last post by:
This is a tip on how to speed up listboxes DRAMATICALLY. Persons that would benefit are those that are constantly updating the rowsource of a listbox/combobox in order to filter and sort the data...
6
by: Imicola | last post by:
Hi, I've recently been tasked with developing a database to store data which has been collected by a lot of different people. I have quite alot of access experience, but not that much on...
0
by: annivanova | last post by:
Hi, I saw posts in Dependent listboxes on access forms, which problem is very similar to my. I’m from Bulgaria and working over to create an MS Access application. I used in my project given code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.