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

Validating a checkbox......

Hi All,

I have a form generated from a Perl script. The number of check boxes
on the form is unknown until the time the form is generated. The
names of the check boxes are created from some values in the database,
based upon other user input.......<crazy, I know>

The user must choose at least one check box.

So, how can I write a javascript routine that will perform checking on
an unknown number of check boxes.

Thanks,

Arthur

Jan 12 '06 #1
4 1401
am****@iwc.net wrote:
Hi All,

I have a form generated from a Perl script. The number of check boxes
on the form is unknown until the time the form is generated. The
names of the check boxes are created from some values in the database,
based upon other user input.......<crazy, I know>

The user must choose at least one check box.

So, how can I write a javascript routine that will perform checking on
an unknown number of check boxes.

/*
By creating a function that creates a collection of checkboxes, then
looping through their "checked" properties. If any of the checked
properties is true, return true. If not, return false.
If there is only one form in the document:
*/

function isOneCheckboxChecked(form){
var f=form.length;
while(f--){
if(form[f].type=="checkbox" && form[f].checked){
return true;
}
}
return false;
}

(Not tested)
Mick


Jan 12 '06 #2

Well, the issue is this: I create an unknown number of check boxes.
Their name comes from a database, so they do not have a simple name
like, check1, check2, etc......

The form is then sent to the user. When the user submits the form, I
want to do some Javascript checking to make sure that they selected at
least one checkbox.........

How to do that if I do not know how many boxes there are, or the
names???

Jan 13 '06 #3
am****@iwc.net wrote:
Well, the issue is this: I create an unknown number of check boxes.
Their name comes from a database, so they do not have a simple name
like, check1, check2, etc......

The form is then sent to the user. When the user submits the form, I
want to do some Javascript checking to make sure that they selected at
least one checkbox.........

How to do that if I do not know how many boxes there are, or the
names???

<script type ="text/javascript">
function isOneCheckboxChecked(form){
var f=form.length;
while(f--){
if(form[f].type=="checkbox" && form[f].checked){
return true;
}
}
alert("OOPS");
return false;
}
</script>

<form
action="javascript:alert('OK');"
onsubmit="return isOneCheckboxChecked(this);">
No need to know how many checkboxes there are, or know their names, or
their religious persuasions...

Mick.


Jan 13 '06 #4

Ahh, sorry, did not read the code all the way through. I'll give it a
whirl.....thanks.

Jan 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
1
by: Miguel Orrego | last post by:
Hi, I have a form that is created dynamically from a recordset, this creates a line for each record together with 2 checkboxes, Yes & No so the source output would be something like this: ...
5
by: Stephen | last post by:
Could someone please help me with some validation. I have to write code which checks to see whether a dropdown list is populated with a value or a checkbox is checked. I want the code to run on the...
2
by: Scott Natwick | last post by:
I would like to validate that a Checkbox is checked on the client-side. I have tried the "requiredfieldvalidator" and the "regularexpressionvalidator", but haven't been able to get either of them...
3
by: Lars Netzel | last post by:
Hi How do I validate a CheckBox with a formvalidator from ASP.NET ? I can't find anyway to do it and I need the look of this validation to look like the rest of the textbox validators on the...
5
by: Bob | last post by:
In a datagridview (vs2005, VB.net) I have two columns that are checkboxes. I need to check that only one of the two can be checked. Its not permissible to have the two selected to true, but they...
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...
7
by: mc | last post by:
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client. I have created a new control as...
0
by: Ned Balzer | last post by:
Hi, Can anyone point me in the direction of a solution for validating multiple checkboxes in an asp.net 2.0 page? 1) This is not a checkboxlist, it is a number of separate checkboxes 2) I do...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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.