473,574 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.......<cr azy, 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 1406
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.......<cr azy, 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 isOneCheckboxCh ecked(form){
var f=form.length;
while(f--){
if(form[f].type=="checkbo x" && 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 isOneCheckboxCh ecked(form){
var f=form.length;
while(f--){
if(form[f].type=="checkbo x" && form[f].checked){
return true;
}
}
alert("OOPS");
return false;
}
</script>

<form
action="javascr ipt:alert('OK') ;"
onsubmit="retur n isOneCheckboxCh ecked(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.....thank s.

Jan 13 '06 #5

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

Similar topics

3
13995
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 dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that...
1
1315
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: <p>Please indicate whether you still use each piece of software detailed below:</p> <form name="apps" method="POST" action="MyAction"> <table...
5
2339
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 on-click of a button. My page has 1 dropdown list and two checkboxes. So I either want the user to choose an item from the dropdownlist OR tick a...
2
3741
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 to work the Checkbox. Any suggestions? Thanks, Scott
3
1200
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 form (which are using RequiredFieldValidators). Please help! Best Regards /Lars
5
8717
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 can both be false. I wrote code in the cellvalidating event as follows. Private Sub Datagrid1_CellValidating(ByVal sender As Object, ByVal e As...
2
6793
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 example of a checkbox group: <td><input type="checkbox" name="trusted" value="1" id="ck_ttt1" onclick="... <td><input type="checkbox"...
7
2439
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 below:- public class ValidifiableCheckBox: CheckBox { public string ValidationValue{ get { return (this.checked ? bool.TrueString : string.Empty); }
0
1623
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 not need to ensure that they are checked, what I am trying to do is lock down the page to prevent possible code injection. So, the checkboxes can...
0
7794
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7710
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7800
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8092
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6437
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5610
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1051
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.