0

Using this jQuery validation plugin.

http://www.benjaminkeen.com/software/rsv/jquery/index.php

I want to validate a checkbox group with JS, but when i use the statement:

rules.push("required,accomodationtype[],Please check all that apply");

or

rules.push("required,accomodationtype\[\],Please check all that apply");

for this kind of checkbox group:

<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_0" value="hotel1">Hotel1<BR>
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_1" value="hotel2">Hotel2<BR>
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_2" value="hotel3">Hotel3<BR>
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_5" value="other"> Other (please specify)<BR>
<INPUT type="text" name="accomodationtypeother" id="accomodationtypeother">

It doesn't validate and it immediately posts the form. I am not sure if I am doing something wrong.

Update

I have custom error handler. Tried Alper's suggestion getting this error message: errorInfo[i][0].focus is not a function

function errorHandler3(f, errorInfo)
{
    for (var i=0; i<errorInfo.length; i++)
    {
        // errorInfo[i][0] contains the form field node that just failed the validation, e.g.
        errorInfo[i][0].focus();
        // errorInfo[i][1] contains the error string to display for this failed field, e.g.
        $.notifyBar({
            cls: "error",
            html: errorInfo[i][1]
        });

    }


    if (errorInfo.length == 0) tcrform_submit();
    return false;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Tural Ali
  • 22,202
  • 18
  • 80
  • 129

2 Answers2

1

I'm not sure that this will help, this post is dealing with radiobuttons but perhaps the same rules apply Validation of radio button group using jQuery validation plugin

Community
  • 1
  • 1
Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
0

there's not enough information for this issue.
Please attach the entire code (js, html), so that we can debug for you.

and for my first glance, I think there must be an "js error" occurred in your code. so I suggest that you should install firebug and make it open focusing "console" tab. then you will see the error message for the senario: "It doesn't validate and it immediately posts the form. "

Siwei
  • 19,858
  • 7
  • 75
  • 95