473,320 Members | 2,122 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,320 software developers and data experts.

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 (gqCategory1Entry1 and
gqCategory2Entry1)

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.selectedIndex
//loop through all form elements
for(var i=0;i<form.length;i++){
var_name=form.elements[i].name;
var_index=form.elements[i].selectedIndex;
if(var_name.substring(0,16)!='gqCategory'){
// if form element is not the current element
// and the division name is the same, raise
//error message
if(var_name!=name&&index!=0&&var_index==index){
alert(var_name);
alert("Duplicate divisions selected! Please choose again.");
elt.selectedIndex=0;
elt.focus();
return false;
}
}
}
return true;
}
</head>

Entry one:
<select name="gqCategory1Entry1" 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="gqCategory2Entry1" 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="gqCategory1Entry2" 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="gqCategory2Entry2" 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 13970
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 (gqCategory1Entry1 and
gqCategory2Entry1)

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.selectedIndex
//loop through all form elements
for(var i=0;i<form.length;i++){
var_name=form.elements[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.substring(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:
gqCategory1Entry2
gqCategory1Entry1

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.selectedIndex;
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.elements;
for (var i=0;i<elems.length;i++) {
if (elems[i] == elt) {continue;} // don't test self
match=elems[i].name.match(gqCategoryRE);
if ( match && entry == +match[2] && // same entry
index == elems[i].selectedIndex) { // same selectedIndex
alert("Duplicate division selected! Please choose again.");
elt.selectedIndex = 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/rasterTriangleDOM.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
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...
5
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...
2
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...
2
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...
4
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...
3
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...
0
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...
2
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.