Eureka... zero tweaking to the logic needed!! Thanks Matt
On 5/19/05, Matthew Woodward <[EMAIL PROTECTED]> wrote:
> Length will give you the number of checkboxes in the variable, not
> the number of checkboxes checked. You just need to loop over the
> checkbox variable and do a check to see if any are checked (how's
> that for redundant?).
>
> This is off the cuff so if this needs tweaking apologies in advance ...
>
> function checkboxcheck(f) {
> var ok = false;
>
> for (var i = 0; i < f.mycheckbox.length; i++) {
> if (f.mycheckbox[i].checked) {
> ok = true;
> }
> }
>
> if (!ok) {
> alert("Check a box please!");
> return false;
> }
>
> return true;
> }
>
> On May 19, 2005, at 12:18 PM, Ryan Everhart wrote:
>
> > Ok guys I know this is easy, so please forgive me. I have a form with
> > a series of checkboxes in it. The checkboxes are all named the same
> > so when the form is submitted I get a comma delimited list of values
> > like 1,4,5,8. I then take that list and put it in my db. Well I'm
> > getting errors from my app now because people are not selecting any
> > check boxes. So I'm trying to right some JS that will make sure at
> > least on check box is check. Below is what I have, but it does seem
> > to be working like I'd like it to.
> >
> > This simply just checks if the value of the boxlist variable coming
> > from the form is greater than 0. Keep in mind the BoxList variable is
> > the name of several check boxes in the form so it should read like
> > 1,4,5,8. It seems that every time I submit the form it passes the
> > 'thisForm.BoxList.length' check every time no matter if any boxes are
> > checked or not.
> >
> > <SCRIPT LANGUAGE="JavaScript">
> > function CheckBoxCheck(thisForm)
> > {
> > if (thisForm.BoxList.length == 0)
> > {
> > alert("Please select at least one checkbox.\n");
> > return false;
> > }
> > }
> > </script>
> >
> >
> > I know I'm just missing something simple. Any thoughts?
> >
> > Thanks,
> > Ryan
> > ----------------------------------------------------------
> > To post, send email to [email protected]
> > To unsubscribe:
> > http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
> > To subscribe:
> > http://www.dfwcfug.org/form_MemberRegistration.cfm
> >
> >
> >
>
> --
> Matthew Woodward
> [EMAIL PROTECTED]
>
>
> ----------------------------------------------------------
> To post, send email to [email protected]
> To unsubscribe:
> http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
> To subscribe:
> http://www.dfwcfug.org/form_MemberRegistration.cfm
>
>
>
----------------------------------------------------------
To post, send email to [email protected]
To unsubscribe:
http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
http://www.dfwcfug.org/form_MemberRegistration.cfm