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;
}
6
  • try using accomationtype instead of accomationtype[] in the jQuery call? Commented Nov 20, 2011 at 14:26
  • it gives error, this field doen't exist Commented Nov 20, 2011 at 14:27
  • Ironically, the not-so-comprehensive demo page for the validator you linked does not show how to validate checkboxes or checkbox groups. I would contact the author if you're set on using that validator. Commented Nov 20, 2011 at 14:53
  • tried, he did'nt answered. Using this validator, because of very simple usage. You can create custom error handler. Commented Nov 20, 2011 at 15:00
  • check this fiddle : jsfiddle.net/Lz5gg/1 it is working as expected. Commented Nov 20, 2011 at 20:01

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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. "

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.