473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Duplicate values in drop down list box

I have a bit of a problem and any help would be much appreciated.

Problem: I have two dropdown list boxes with same data(all data
driven).
These are used for two separate entries.
For every entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Ent ry1 and
gqCategory2Entr y1)

This part works.
The second entry is the problem: When I choose a value for Entry
Two that is the same as in entry one it thinks that "Dubplicate
Divisons have been selected").

WHen in fact these are two separate entries.

Code:
<head>
//Enry number one...no Duplicates
function check_selection (elt){
//check for duplicate selections
var form=elt.form;
var name=elt.name;
var index=elt.selec tedIndex
//loop through all form elements
for(var i=0;i<form.leng th;i++){
var_name=form.e lements[i].name;
var_index=form. elements[i].selectedIndex;
if(var_name.sub string(0,16)!=' gqCategory'){
// if form element is not the current element
// and the division name is the same, raise
//error message
if(var_name!=na me&&index!=0&&v ar_index==index ){
alert(var_name) ;
alert("Duplicat e divisions selected! Please choose again.");
elt.selectedInd ex=0;
elt.focus();
return false;
}
}
}
return true;
}
</head>

Entry one:
<select name="gqCategor y1Entry1" maxlength="48" tabindex = 20
onChange="check _selection(this )" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
<select name="gqCategor y2Entry1" maxlength="48" tabindex = 20
onChange="check _selection(this )" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
------------
Entry TWO:
<select name="gqCategor y1Entry2" maxlength="48" tabindex = 20
onChange="check _selection(this )" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
<select name="gqCategor y2Entry2" maxlength="48" tabindex = 20
onChange="check _selection(this )" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
Jul 20 '05 #1
1 14008
ma**@idiom.com (marx) writes:
I have a bit of a problem and any help would be much appreciated.

Problem: I have two dropdown list boxes with same data(all data
driven).
You have two select elements with identical options.
These are used for two separate entries.
I.e., you have *four* select elements with identical options,
grouped into two "entries".
For every entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Ent ry1 and
gqCategory2Entr y1)

This part works.
The second entry is the problem: When I choose a value for Entry
Two that is the same as in entry one it thinks that "Dubplicate
Divisons have been selected").
So the code checks all select elements, not only the ones in the same
"entry".
WHen in fact these are two separate entries.

Code:
<head>
//Enry number one...no Duplicates
function check_selection (elt){
//check for duplicate selections
var form=elt.form;
var name=elt.name;
var index=elt.selec tedIndex
//loop through all form elements
for(var i=0;i<form.leng th;i++){
var_name=form.e lements[i].name;
var_index=form. elements[i].selectedIndex;
These variables are not declared, so they become global variables.
No need for that. Put a "var" in front.
if(var_name.sub string(0,16)!=' gqCategory'){


You only check that they have the same first 16 characters. That misses
the distinction between entries, which is much later in the name.

Example names:
gqCategory1Entr y2
gqCategory1Entr y1

The entry number is past the first 16 characters, and is never checked.

In case you ever need more than 9 or 10 categories or entries, let's
make this work for any number:

---
function check_selection (elt){
var gqCategoryRE = /^gqCategory(\d+ )Entry(\d+)$/;
var index = elt.selectedInd ex;
if (index == 0) {return true;} // always legal
var match = elt.name.match( gqCategoryRE);
if (!match) { return; } // not a gqCategory at all.
var category = +match[1];
var entry = +match[2];

var elems = elt.form.elemen ts;
for (var i=0;i<elems.len gth;i++) {
if (elems[i] == elt) {continue;} // don't test self
match=elems[i].name.match(gqC ategoryRE);
if ( match && entry == +match[2] && // same entry
index == elems[i].selectedIndex) { // same selectedIndex
alert("Duplicat e division selected! Please choose again.");
elt.selectedInd ex = 0;
elt.focus(0);
return false;
}
}
return true;
}
---

Tested in Opera 7 with the supplied select elements.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

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

Similar topics

2
3617
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I would like the user to be able to start filling in the form, then get to one of the dropdown lists (ex: Service Type) and realize that the dropdown...
5
2230
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so that it would bring back all attachments at all companies or all locations at a company? Thank you, Rob. Private Sub Page_Load(ByVal sender As...
2
1391
by: R-D-C | last post by:
Hi, got a drop-down list on a windows form in VS.NET2003. In the form load when NOT a postback, we add four values to the drop-down list. These appear in Internet Explorer. When you click a button on the form, the value selected in the drop-down is supposed to be put in a label's Text property. However, when you click the button, the...
2
12347
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations....
4
2829
by: gurvar | last post by:
Hi I'm trying to remove duplicate elements from a Drop Down List Fill in VB.net. Following code worked well with vb6. But I'm getting index out of range if I try to translate it to vb.net code at line#4. Any possible clues will be appreciated. Thanks. 'To distill the Combo Element NumY = Combo5.ListCount + 1 '''''''''''''''Line1 For...
3
1855
by: Jim McGivney | last post by:
In VWD I have an aspx page with a DropDownList control. The DropDownList is populated from a column from a table in an Access database. If there are duplicate values in the column they are added to the DropDownList. Is there a way to eliminate duplicate items on the DropDownList ? Thanks, Jim
0
1845
by: kajir | last post by:
Hi, I am new at using ASP.Net 2.0. I have various drop down lists on my master page. They refer to an SQL database. I also have a menu on the master page. I can select the values in the drop down list and generate reports using Reporting services and parameters on the default page. Now I want to create another kind of report on...
2
1784
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my code that does this. I have left out the portion that connects to my server and the query, but this should be enough to show what I am doing....
3
5866
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I analyze each word and rebuild the text string as a combination of correct text (not misspelled) and a drop down list offering suggestions in place of...
1
7452
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5354
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.