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

Single / Multiple Checkbox Validation

Hi,

I have a dynamically generated form, and each listing contains a checkbox named 'del'.
The users checks the 'del' checkbox next to each listing they wish to delete, and click the submit button. If there are multiple listings/checkboxes on the page, then the script I have works quite well, but if there is only one checkbox displayed on the page. If there is only one checkbox, and the user clicks the submit button, it still submits the form even if the single checkbox is not checked.

Here is my script:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language="JavaScript1.2">
  2. function valDelForm(theForm)
  3. {
  4. var filledIn = false;    
  5.  
  6.     // Use the length property to iterate through each Checkbox
  7.     // to determine if a selection has been made
  8.        for (var counter=0; counter<theForm.del.length; counter++)
  9.        if (theForm.del[counter].checked == true){
  10.        filledIn = true;
  11.  
  12.        //else{
  13.        if (theForm.del.checked == true){
  14.        filledIn = true;
  15.        }
  16.       // }
  17.     }
  18.  
  19.        if (filledIn == false){
  20.        alert('Please select a listing to delete!');
  21.        return(false);
  22.     }  
  23.  
  24.  return(true);
  25. }
  26. </script>
This is how the script is called from the opening form tag: onSubmit="return valDelForm(this)"
Jun 2 '08 #1
1 3409
acoder
16,027 Expert Mod 8TB
If there's only one checkbox, the length will be undefined, so first make a check that length is defined. If not, use the single checkbox validation code, otherwise check all checkboxes.
Jun 2 '08 #2

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

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please give me some clues on how to track the right answers in multiple-choice type questions (using checkbox) and single-choice questions (rdio buttons) and also how to store the right...
1
by: Eric | last post by:
Hi all, I have a form that generates a dynamic number of rows from a value passed in via querystring. I have a one static row in my form with a "master" checkbox that I have deemed "Select...
3
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of...
5
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
7
by: karen987 | last post by:
The code below is for a checkbox, in a form on an asp page. I want to make it mandatory for the user to click it. The other validation statements work fine, this one causes a problem though. The...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: forbes | last post by:
Hi, I have a form that contains multiple groups of checkboxes that act like radio buttons (at the clients insistance). There is one text field that is required and 28 checkbox groups. Here an...
0
by: Ned Balzer | last post by:
I posted this this morning but it never went through, so I am trying again -- apologies for the duplication if so. I need to validate several checkboxes on an asp.net 2.0 page. I don't need to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.