473,396 Members | 1,933 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,396 software developers and data experts.

How to deselect the more selected options from combobox?

I have a combobox, in that i have taken list of districts so i have provide a facility to select max 5 districts. If user by mistake select more than that i have to give an alert and when user click on ok of the alert msg the the more select option have to deselect. How to do that i am tring on code. see below

Expand|Select|Wrap|Line Numbers
  1. function validateListBox()
  2. {
  3. //debugger;
  4. selectedArray=[];
  5.   var selObj = document.getElementById('type1');
  6.   var i;
  7.   var count = 0;
  8.   var no = 0;
  9.   for (i=0; i<selObj.options.length; i++) {
  10.     if (selObj.options[i].selected)
  11.     {
  12.       statelist = selObj.options[i].text;
  13.       count++;
  14.       selectedArray.push(statelist);
  15.  
  16.       }
  17.       if(count > 4)
  18.       {
  19.         //debugger;
  20.         alert("Select four "+type+" at a time only.");
  21.  
  22.         if(i==selObj.options.length-1)
  23.         {
  24.             for (i=selObj.options.length-1; i>0; i--) 
  25.             {
  26.                 if (selObj.options[i].selected)
  27.                 {    
  28.                     no++;
  29.                     if(no>4)
  30.                     {
  31.                         selObj.options[i].selected=false;
  32.                         return false;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.         else
  38.         {
  39.         selObj.options[i].selected=false;
  40.         return false;
  41.         }
  42.       }
Oct 20 '10 #1
1 1987
Dormilich
8,658 Expert Mod 8TB
it doesn’t look wrong at first glance. what part of your code is not working?
Oct 20 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MaJoHu | last post by:
I've got a list where u can select some products. It's something like this: <SELECT NAME='Product' MULTIPLE SIZE='10'> <% 'Get every possible item from items table SQL = "SELECT DISTINCT...
1
by: Keiron Waites | last post by:
Hi, I have two select fields with the multiple attribute so you can see all options. When a user clicks on one form, I would like to deselect anything from the other form. Is there a way to do...
15
by: TJ Walls | last post by:
Hello All, Is it possible to create a <select> element with no selected options? I have tried setting the selectedIndex attribute to -1, but as far as I can tell this only works for <select...
1
by: ReidarT | last post by:
How can I show more than one field in a combobox? regards reidarT
1
by: dev.amit | last post by:
Hello friends Can anyone tell me how to deselect the item selected in the list box If Me!lb_test_property.ItemsSelected.Count > 0 Then For Each varItem In Me!lb_test_property.ItemsSelected...
0
by: sloan | last post by:
Asp.Net 2.0 Inside a repeater, I'm trying to do a linkbutton with a OnClientClick <asp:LinkButton ID="lnbSelect" runat="server"...
1
by: julianomartins | last post by:
Hi friends, how I make to recoup the value of database and to keep selected in combobox to edit my form? in script below it is selected field of the table that possesss id of the first item of...
3
by: royd16 | last post by:
Hi!, can some help me with a problem? Here are my tables: User, Profiles, and one for "Profiles per user" In the last one, I save the ID of the user and the ID of the profiles for that user....
5
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...

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.