Question

Select Box - No Duplicates

Asked by: nik_crash

Hello Sir/Ma'am,
  I am hoping somebody can help with this: I have a form with several select boxes which all have the same options (the options represent nba team). I would like to validate this form to require that the same option is not selected on more than one select box?

For Example:

<Select name=nbateam1>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam2>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam3>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

Thank u very much..

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-01-06 at 20:14:26ID20843066
Tags

duplicate

,

select

Topic

JavaScript

Participating Experts
3
Points
125
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Duplicate text box
    I have a text box object on my VB form. How can I duplicate it in a run-time mode?
  2. DreamWeaver Validate Form for Duplicates
    How can I validate a form to check the database for a duplicate entry?
  3. FrontPage Validation says duplicate field names
    Hello! I have a form and I wish to place validation on several fields. When I put validation on even a single field I cannot save the page because I get an error that duplicate field names exist with validation. HELP!
  4. Validation List Without Duplication
    Dear All... Supose i have the list in Sheet 1 Col A1:A10 like this : A 1 Car 2 Truck 3 Car 4 Car 5 Bus 6 Bus 7 Truck 8 Truck 9 Bus 10 Car And i like to make validation in Sheet 2 Cell B2 with list from data above. Is it possible to mak...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jaysolomonPosted on 2004-01-06 at 20:21:20ID: 10058898

how about this

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
function getSelectText(selObj){
      return selObj.options[selObj.selectedIndex].text;
}
function validate(fObj){
      var selTxt1 = getSelectText(fObj["nbateam1"]);
      var selTxt2 = getSelectText(fObj["nbateam2"]);
      var selTxt3 = getSelectText(fObj["nbateam3"]);
      if(selTxt1 == selTxt2 || selTxt1 == selTxt3){
            alert("You cannot choose the same team");      
                  return false;
      }
      if(selTxt2 == selTxt1 || selTxt2 == selTxt3){
            alert("You cannot choose the same team");      
                  return false;
      }
      if(selTxt3 == selTxt1 || selTxt3 == selTxt2){
            alert("You cannot choose the same team");      
                  return false;
      }
      return true;
}
//End-->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validate(this);">
<Select name=nbateam1>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam2>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam3>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

 

by: thirdPosted on 2004-01-06 at 23:35:20ID: 10059665

or since each team has the same index for each select box, you can use the selectedIndex property for checking instead of text.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin

function validate(obj){
       if((obj.nbateam1.selectedIndex == obj.nbateam2.selectedIndex) || (obj.nbateam1.selectedIndex == obj.nbateam3.selectedIndex) || (obj.nbateam2.selectedIndex == obj.nbateam3.selectedIndex)){
          alert("You cannot choose the same team");    
               return false;
     }
     return true;
}
//End-->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validate(this);">
<Select name=nbateam1>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam2>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>

<Select name=nbateam3>
<option>Lakers</option>
<option>Celtics</option>
<option>Spurs</option>
</Select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

 

by: ZeroPagePosted on 2004-01-07 at 03:03:40ID: 10060655

Here my proposal:


<html>
<head>
<script>
var team = ["Lakers", "Celtics", "Spurs"];
function init(){
  theForm = document.forms[0];
  for(i=1;i<=3;i++){
    opt = theForm["nbateam"+i].options;
    opt.length=1;
    for(j=0;j<team.length;j++){
      opt[opt.length] = new Option(team[j], team[j]);
    }
    theForm["nbateam"+i].onchange = function(){reSelect(this)};
  }
}
function reSelect(theSel){
  theForm = theSel.form;
  sOpt = new Array();
  for(i=1;i<=3;i++){
    if(theForm["nbateam"+i].selectedIndex>0){
      sOpt[sOpt.length] = theForm["nbateam"+i].value;
    };
  }
  for(i=1;i<=3;i++){
    sVal = theForm["nbateam"+i].value;
    opt = theForm["nbateam"+i].options;
    opt.length=1;
    if(sVal > ""){
      opt[opt.length] = new Option(sVal, sVal,true,true);
    }
    for(j=0;j<team.length;j++){
      nVal = team[j];
      for(k=0;k<sOpt.length;k++){
        if(nVal==sOpt[k]){
          nVal = "";
        }
      }
      if(nVal > ""){
        opt[opt.length] = new Option(nVal, nVal);
      }
    }
  }
}
</script>
</head>
<body onLoad="init()">
<form>
<Select name=nbateam1>
<option>--Select--
</Select>

<Select name=nbateam2>
<option>--Select--
</Select>

<Select name=nbateam3>
<option>--Select--
</Select>
</form>
</body>
</html>

 

by: jaysolomonPosted on 2004-01-07 at 05:57:31ID: 10061740

can someone tell me what was wrong with what i posted?

 

by: ZeroPagePosted on 2004-01-07 at 07:43:29ID: 10062641

My is simply better. Try it and you will see.

 

by: jaysolomonPosted on 2004-01-07 at 07:48:04ID: 10062683

dunno about the "simply better" i guess that is one's opinion

 

by: ZeroPagePosted on 2004-01-07 at 07:59:09ID: 10062775



You say your solution telling the user "Wrong Answer!" is same or better then reducing the options to available options???


 

by: jaysolomonPosted on 2004-01-07 at 08:08:26ID: 10062863

My answer is not WRONG!

he/she ask to validate and make sure the selects did NOT contain the same in each.Thats what mine does.

So if you wanna argue go ahead i do not have time for it. Maybe you and the other point hounds can argue with each other.

Better yet instead of filling a question up with your blog why don't you step up to my challange and do something usefull with your time.

If your not a point hound you will step up to the challange.

http:Q_20842335.html

 

by: ZeroPagePosted on 2004-01-07 at 08:13:44ID: 10062926

Calm down jAyMod :)

 

by: jaysolomonPosted on 2004-01-07 at 08:16:46ID: 10062951

thats what i thought just another point hound

BTW i am not a mod and never will be

 

by: ZeroPagePosted on 2004-01-07 at 08:19:36ID: 10062978

you say it.

 

by: thirdPosted on 2004-01-07 at 16:46:44ID: 10067254

calm down, guys.

IMO, there is nothing wrong with jAY's proposal that's why the first word on my comment is "or". ZeroPage's suggestion is also good (more user-friendly) but sacrifices speed since it reloads the items each time you change the value of each select box. it's best for lesser items but has a bug in NS.

 

by: nik_crashPosted on 2004-01-08 at 00:20:32ID: 10069077

Sir/M'a,am;
 Thank u for answering my question especially zeropage that idea is my need but the data in my select is populated from database using ms sql?How can i to this..

Thank u..

 

by: ZeroPagePosted on 2004-01-08 at 04:58:46ID: 10070951

Your mssql is server side, and upper scripting is browser side.
So you need some sort of server scripting.
I suppose you can use ASP and VBScript to read the team names on server side and put them as part of the http page sent as response to browser.
So you need to feed this string with the team names:

var team = ["Lakers", "Celtics", "Spurs"];

I can not test the exact syntax for your ASP right now, but it is something like this:

<html>
<head>
<script>
var team = [
<%
  'make connection to MSSQL and fetch the team names
  'put them one by one in quotas and separated by a coma.

  %>"<% = rs.Field("teamname") %>", <%

%>
    " " ];
team.length = team.length-1;  // remove the last empty team name

function init(){
  theForm = document.forms[0];
  for(i=1;i<=3;i++){
    opt = theForm["nbateam"+i].options;
    opt.length=1;
    for(j=0;j<team.length;j++){
      opt[opt.length] = new Option(team[j], team[j]);
    }
    theForm["nbateam"+i].onchange = function(){reSelect(this)};
  }
}
function reSelect(theSel){
  theForm = theSel.form;
  sOpt = new Array();
  for(i=1;i<=3;i++){
    if(theForm["nbateam"+i].selectedIndex>0){
      sOpt[sOpt.length] = theForm["nbateam"+i].value;
    };
  }
  for(i=1;i<=3;i++){
    sVal = theForm["nbateam"+i].value;
    opt = theForm["nbateam"+i].options;
    opt.length=1;
    if(sVal > ""){
      opt[opt.length] = new Option(sVal, sVal,true,true);
    }
    for(j=0;j<team.length;j++){
      nVal = team[j];
      for(k=0;k<sOpt.length;k++){
        if(nVal==sOpt[k]){
          nVal = "";
        }
      }
      if(nVal > ""){
        opt[opt.length] = new Option(nVal, nVal);
      }
    }
  }
}
</script>
</head>
<body onLoad="init()">
<form>
<Select name=nbateam1>
<option>--Select--
</Select>

<Select name=nbateam2>
<option>--Select--
</Select>

<Select name=nbateam3>
<option>--Select--
</Select>
</form>
</body>
</html>


Good luck.

 

by: nik_crashPosted on 2004-01-08 at 19:06:17ID: 10077516

Sir;
 Last question, I have a stored procedure to call when I select the team, my problem is how can i get the corresponding ID of that teamname? using this...

var team = [
<%
  'make connection to MSSQL and fetch the team names
  'put them one by one in quotas and separated by a coma.

  %>"<% = rs.Field("teamname") %>", <%

%>
    " " ];

Thank u very much...

 

by: nik_crashPosted on 2004-01-09 at 00:19:48ID: 10078548

Sir,
 Regarding to my email earlier, I add corresponding tag id & '-', to every game like this one & I create a function that extract the no before '-'.
 My question is where can i place the function that i created to get the value of '44','45','46'?

Thank u very much..

var team =
[
  "44-(3) Lakers vs (4) Dallas",
  "45-(5) Chicago vs (6) Nets",
  "46-(7) Clippers vs (8) Celtics"
];
team.length = team.length-1;  // remove the last empty team name

function init(){

  theForm = document.forms[0];
  for(i=1;i<=3;i++){
    opt = theForm["cboCock"+i].options;
    opt.length=1;
    for(j=0;j<team.length;j++){

      opt[opt.length] = new Option(team[j], team[j]);
    }
    theForm["cboCock"+i].onchange = function(){reSelect(this)};
  }
}


 function splitWords(sAll)  
 {
 
 var sFirst;
 var sLast;
 var iPos;

 iPos = sAll.indexOf("-");

       if (iPos != 0)
       {
             sFirst = sAll.substr(0 , iPos);
             sLast = sAll.substr(iPos+1,sAll.length - iPos - 1);
       }
}


function reSelect(theSel){
  theForm = theSel.form;
  sOpt = new Array();
  for(i=1;i<=3;i++){
    if(theForm["cboCock"+i].selectedIndex>0){
      sOpt[sOpt.length] = theForm["cboCock"+i].value;
    };
  }
  for(i=1;i<=3;i++){
    sVal = theForm["cboCock"+i].value;
    opt = theForm["cboCock"+i].options;
    opt.length=1;
    if(sVal > ""){
      opt[opt.length] = new Option(sVal, sVal,true,true);
    }
    for(j=0;j<team.length;j++){
      nVal = team[j];
      for(k=0;k<sOpt.length;k++){
        if(nVal==sOpt[k]){
          nVal = "";
        }
      }
      if(nVal > ""){
        opt[opt.length] = new Option(nVal, nVal);
      }
    }
  }
}

 

by: jaysolomonPosted on 2004-01-30 at 13:01:59ID: 10238388

This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately one week.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hs5

jAy
EE Cleanup Volunteer

 

by: jaysolomonPosted on 2004-02-09 at 08:17:53ID: 10311238

I will leave the following recommendation for this question in the Cleanup topic area:

Split: jaysolomon {http:#10058898} & third {http:#10059665} & ZeroPage {http:#10070951}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...