473,320 Members | 2,180 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.

List Box Validation

65
hi,

Following function i am using for validating list box. In list box user can select only 5 item .

Expand|Select|Wrap|Line Numbers
  1.  function Validate()
  2.     {
  3.           var lblCount=0;
  4.           var lbGenre = document.getElementById('<% Response.Write(lstbox.UniqueID); %>');
  5.            for(var x = 0; x < lbGenre.options.length; x++)
  6.             {
  7.                  if(lbGenre.options[x].selected)
  8.                  {
  9.                     lblCount+=1;
  10.                  }
  11.             }
  12.             if(lblCount > 5)
  13.             {              
  14.               alert("maximum five!");  
  15.               return false;
  16.             }
  17.     }

That is working fine. i want to how to unselect the six item selected from list box?


regards
veena
Oct 15 '09 #1

✓ answered by ivosilva

Hello, veenna!

I have tested the following code in IE8, Firefox 3.5 and Chrome 3.0 and it seems to work fine (I have no previous versions of IE installed to test it).

Expand|Select|Wrap|Line Numbers
  1. function validate() {
  2.             var max = 2;
  3.             var lblCount = 0;
  4.             var lbGenre = document.getElementById('<% Response.Write(lstbox.UniqueID); %>');
  5.  
  6.             for(var x = 0; x < lbGenre.options.length; x++) {
  7.  
  8.                 if(lbGenre.options[x].selected) {
  9.  
  10.                     lblCount++;
  11.  
  12.                     if(lblCount > max) {
  13.                         lbGenre.options[x].selected = false;
  14.                     }
  15.                 }
  16.             }
  17.  
  18.             if(lblCount > max) {
  19.                 alert("You can only select a maximum of " + max + " options!");
  20.                 return false;
  21.             }
  22.         }
Best regards

7 2500
veenna
65
Can any one please tell me How to unselect one item from list box?

Regards
Veena
Oct 16 '09 #2
RamananKalirajan
608 512MB
Hi Veena,
Its difficult to unselect a particular option in multiselect.

Thanks and Regards
Ramanan Kalirajan
Oct 16 '09 #3
Dormilich
8,658 Expert Mod 8TB
@RamananKalirajan
doesn’t the usual ctrl+click work? (untested)
Oct 16 '09 #4
RamananKalirajan
608 512MB
She is asking about unselcting through JS.. It can be done using document.getElementById('sampleSelect').options[selectedIndex].selected="false", this will work in Mozilla but not in IE. This is a problem.

Thanks and Regards
Ramanan Kalirajan
Oct 16 '09 #5
Hello, veenna!

I have tested the following code in IE8, Firefox 3.5 and Chrome 3.0 and it seems to work fine (I have no previous versions of IE installed to test it).

Expand|Select|Wrap|Line Numbers
  1. function validate() {
  2.             var max = 2;
  3.             var lblCount = 0;
  4.             var lbGenre = document.getElementById('<% Response.Write(lstbox.UniqueID); %>');
  5.  
  6.             for(var x = 0; x < lbGenre.options.length; x++) {
  7.  
  8.                 if(lbGenre.options[x].selected) {
  9.  
  10.                     lblCount++;
  11.  
  12.                     if(lblCount > max) {
  13.                         lbGenre.options[x].selected = false;
  14.                     }
  15.                 }
  16.             }
  17.  
  18.             if(lblCount > max) {
  19.                 alert("You can only select a maximum of " + max + " options!");
  20.                 return false;
  21.             }
  22.         }
Best regards
Oct 18 '09 #6
RamananKalirajan
608 512MB
In IE6, it wont be working yaar...

Thanks and Regards
Ramanan Kalirajan
Oct 19 '09 #7
Hello, RamananKalirajan!

I've just tested it under IE6 and it works ok.

Have you tested my code using IE6?

Best regards!
Oct 19 '09 #8

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

Similar topics

3
by: Ray | last post by:
Hi Groups To achieve the visual effect of the page http://www.freewebs.com/nsl/test1.html but remove the table and use CSS, I wrote a page like this http://www.freewebs.com/nsl/test2.html I...
4
by: adam.lock | last post by:
Hi I have a form which has 10 list boxes on it, each with a select option with values 0 to 3. Once the user submits the form, I want to validate that only three of the list boxes have been...
9
by: DangerD321 | last post by:
Hi I am creating a relational database for school work and have got stuck on a simple problem i have a table called organisation and one of its fields is organsiation id (primary key) in...
9
by: Bob Alston | last post by:
I have a drop down combo box that gives the user to enter an item not in the list by adding it to the list. The list is a table. It works fine on Access2003 but fails on Access2002/XP. ON XP, it...
7
by: David Laub | last post by:
I have stumbled across various Netscape issues, none of which appear to be solvable by tweaking the clientTarget or targetSchema properties. At this point, I'm not even interested in "solving"...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
4
by: smowen | last post by:
In Excel I have a validation list which takes values from cells in other worksheets, so the validation list is made of up formulas with cell references in. I want to have a macro which...
1
by: monu121 | last post by:
hello friends, i am not expert in vb 6.0.i am working in a product which is vb 6.0 based. i am creating two drop down list by writting some text in one ini file(this relate to...
1
by: Maninder Karir | last post by:
Hi, Basically I have 3 workbooks (A, B and C) Workbook A is used to retrieve all the information Workbook B contains a number of Lists used in workbook A (including a list of suppliers)...
1
by: jitupatil2007 | last post by:
hi friends i am reading a csv file using string array and after that to keep a validation check i have added the array to list and using list i am accessing the records correctly but i have a...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.