Evaluate Options in Dropdown for Unique Selection?

J

JL

Does anyone have any ideas on this please?

I don't know how to evaluate the no-blank selections against each other from
a form as follows: .

I have a form with 6 dropdown fields, each containing a selection of 30
options (the 30 options are the same for each dropdown list).
The user needs to select 'one of the 30 options' from each dropdown
selection, but each option they select must be unique (no duplicate
selections) or it must be left blank.
E.g. The user can select Option3 within "dropdown1", but must select a
different option for the other dropdowns - OR leave them unselected.

Any help is greatly appreciated...

JL
 
K

kaeli

E.g. The user can select Option3 within "dropdown1", but must select a
different option for the other dropdowns - OR leave them unselected.

Any help is greatly appreciated...

JL

I don't suppose they're all in the same order so that the selectedIndex
would be the same if the option were the same?

--
 
J

JL

The dropdown options would be dynamically populated from a database list (so
would be in the same order for the 6 dropdown menus).

The option labels would be the "candidate names" and the option value would
be the "candidate Ids". When submitted, these would be inserted in to a
database table along with the user's details (as a voting system).

Could this be done having the list like this?


| In article <[email protected]>,
| (e-mail address removed) enlightened us with...
| > E.g. The user can select Option3 within "dropdown1", but must select a
| > different option for the other dropdowns - OR leave them unselected.
| >
| > Any help is greatly appreciated...
| >
| > JL
| >
| >
| >
|
| I don't suppose they're all in the same order so that the selectedIndex
| would be the same if the option were the same?
|
| --
| --
| ~kaeli~
| When you choke a smurf, what color does it turn?
| http://www.ipwebdesign.net/wildAtHeart
| http://www.ipwebdesign.net/kaelisSpace
|
 
J

Joakim Braun

JL said:
Does anyone have any ideas on this please?

I don't know how to evaluate the no-blank selections against each other from
a form as follows: .

I have a form with 6 dropdown fields, each containing a selection of 30
options (the 30 options are the same for each dropdown list).
The user needs to select 'one of the 30 options' from each dropdown
selection, but each option they select must be unique (no duplicate
selections) or it must be left blank.
E.g. The user can select Option3 within "dropdown1", but must select a
different option for the other dropdowns - OR leave them unselected.

Any help is greatly appreciated...

JL

How about regenerating the dropdowns as new selections are made?
You have a base set of 30 options, then:
* Fill first dropdown with all options
* Fill second dropdown with all options except the one selected in the first
dropdown
* Fill third dropdown with all options except what's selected in first and
second dropdowns, etc.

When a selection is made, you regenerate all dropdowns "downstream" from the
one modified.

Might be a bit slow, but at least the user can't select a nonexistent item.

Joakim Braun
 
K

kaeli

The dropdown options would be dynamically populated from a database list (so
would be in the same order for the 6 dropdown menus).

The option labels would be the "candidate names" and the option value would
be the "candidate Ids". When submitted, these would be inserted in to a
database table along with the user's details (as a voting system).

Could this be done having the list like this?

It could be done no matter how the list was built, it's just a lot
easier if the selectedIndex is the same for equal fields.

I made a little example with 3 selects with 6 options each. Tested in
IE6. Checks only for duplicates. If you want to make sure there is a
selection, make sure the first element is a "Select one" type, then
check for a being equal to 0 as well as being equal to the next a[i+
1].

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function verify(frm)
{
var a = new Array(frm.select_1.selectedIndex,frm.select_
2.selectedIndex,frm.select_3.selectedIndex);
a.sort();
for(i=0; i<a.length; i++)
{
if(a==a[i+1])
{
alert("error: duplicates");
return false;
}
}
return true;
}
</script>
</head>

<body>
<form name="f1" onSubmit="return verify(this)">
<select name="select_1">
<option value='0'>zero</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
<option value='5'>five</option>
</select>
<br>
<select name="select_2">
<option value='0'>zero</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
<option value='5'>five</option>
</select>
<br>
<select name="select_3">
<option value='0'>zero</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
<option value='5'>five</option>
</select>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

--
 
J

JL

Hi Kaeli,

I couldn't get the page to work (nothing happened when I made the same
selections and pressed submit) - was there something else I needed to do to
get it to work?

Thanks
JL


| It could be done no matter how the list was built, it's just a lot
| easier if the selectedIndex is the same for equal fields.
|
| I made a little example with 3 selects with 6 options each. Tested in
| IE6. Checks only for duplicates. If you want to make sure there is a
| selection, make sure the first element is a "Select one" type, then
| check for a being equal to 0 as well as being equal to the next a[i+
| 1].
|
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
| "http://www.w3.org/TR/REC-html40/loose.dtd">
| <html>
| <head>
| <title> New Document </title>
| <script type="text/javascript">
| function verify(frm)
| {
| var a = new Array(frm.select_1.selectedIndex,frm.select_
| 2.selectedIndex,frm.select_3.selectedIndex);
| a.sort();
| for(i=0; i<a.length; i++)
| {
| if(a==a[i+1])
| {
| alert("error: duplicates");
| return false;
| }
| }
| return true;
| }
| </script>
| </head>
|
| <body>
| <form name="f1" onSubmit="return verify(this)">
| <select name="select_1">
| <option value='0'>zero</option>
| <option value='1'>one</option>
| <option value='2'>two</option>
| <option value='3'>three</option>
| <option value='4'>four</option>
| <option value='5'>five</option>
| </select>
| <br>
| <select name="select_2">
| <option value='0'>zero</option>
| <option value='1'>one</option>
| <option value='2'>two</option>
| <option value='3'>three</option>
| <option value='4'>four</option>
| <option value='5'>five</option>
| </select>
| <br>
| <select name="select_3">
| <option value='0'>zero</option>
| <option value='1'>one</option>
| <option value='2'>two</option>
| <option value='3'>three</option>
| <option value='4'>four</option>
| <option value='5'>five</option>
| </select>
| <br>
| <input type="submit" value="Submit">
| </form>
| </body>
| </html>
|
| --
| --
| ~kaeli~
| Never say, "Oops!"; always say, "Ah, interesting!"
| http://www.ipwebdesign.net/wildAtHeart
| http://www.ipwebdesign.net/kaelisSpace
|
 
J

JL

Hi Joakim,

Yes - this would be the ideal solution (regenerating the dropdowns as new
selections are made) but how would I do this?
Can it be done using ASP at all (rather than client side JavaScript)?
Anyone know?

Thanks
JL


| How about regenerating the dropdowns as new selections are made?
| You have a base set of 30 options, then:
| * Fill first dropdown with all options
| * Fill second dropdown with all options except the one selected in the
first
| dropdown
| * Fill third dropdown with all options except what's selected in first and
| second dropdowns, etc.
|
| When a selection is made, you regenerate all dropdowns "downstream" from
the
| one modified.
|
| Might be a bit slow, but at least the user can't select a nonexistent
item.
|
| Joakim Braun
 
M

Michael Winter

Yes - this would be the ideal solution (regenerating the dropdowns as new
selections are made) but how would I do this?

A question, first: do the various SELECT elements have meaning? You said
that this is for a voting system, so does a candidate in an earlier SELECT
element have preference over a candidate in a lower element? If so, this
suggestion wouldn't be a good idea as the user might have trouble changing
the order of candidates.
Can it be done using ASP at all (rather than client side JavaScript)?
Anyone know?

You could submit the page and rewrite it with each selection, but this
isn't the same effect. Unless order is irrelevant, Kaeli's suggestion is
the best client-side validation technique.

Mike
 
J

JL

Hi,

The form is intended to just pick 6 candidates from the 30 available - all
six that are selected are of the same hierarchy (it doesn't matter which
order they are picked in).

Has anyone seen any scripts/applications anywhere for this type of voting
system?

Thanks all.....

JL


| On Wed, 21 Apr 2004 23:04:17 +0100, JL <[email protected]>
| wrote:
|
| > Yes - this would be the ideal solution (regenerating the dropdowns as
new
| > selections are made) but how would I do this?
|
| A question, first: do the various SELECT elements have meaning? You said
| that this is for a voting system, so does a candidate in an earlier SELECT
| element have preference over a candidate in a lower element? If so, this
| suggestion wouldn't be a good idea as the user might have trouble changing
| the order of candidates.
|
| > Can it be done using ASP at all (rather than client side JavaScript)?
| > Anyone know?
|
| You could submit the page and rewrite it with each selection, but this
| isn't the same effect. Unless order is irrelevant, Kaeli's suggestion is
| the best client-side validation technique.
|
| Mike
|
| --
| Michael Winter
| (e-mail address removed) (replace ".invalid" with ".uk" to reply)
 
K

kaeli

Hi Kaeli,

I couldn't get the page to work (nothing happened when I made the same
selections and pressed submit) - was there something else I needed to do to
get it to work?

Aside from being careful about line breaks, no.
You did join the lines after your copy/paste, right? Word-wrap can do
bad things.

Go here and see if it works.
http://www.ipwebdesign.net/test4.html

It worked in IE6 and NN7 for me.

--
 
J

JL

Hi Kaeli,

Yes - it works now.
It looks like this will do the trick and it's such a small code size too!

Thank you very, very much....
:)

JL



| In article <[email protected]>,
| (e-mail address removed) enlightened us with...
| > Hi Kaeli,
| >
| > I couldn't get the page to work (nothing happened when I made the same
| > selections and pressed submit) - was there something else I needed to do
to
| > get it to work?
|
| Aside from being careful about line breaks, no.
| You did join the lines after your copy/paste, right? Word-wrap can do
| bad things.
|
| Go here and see if it works.
| http://www.ipwebdesign.net/test4.html
|
| It worked in IE6 and NN7 for me.
|
| --
| --
| ~kaeli~
| If it's tourist season, why can't we shoot them?
| http://www.ipwebdesign.net/wildAtHeart
| http://www.ipwebdesign.net/kaelisSpace
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top