0

I am using jQuery Validation plugin for a form. When the form is not validated, I am getting the correct error message, I would just like to place it in another location.

Right now the error label is showing up under the first checkbox label(Check 1). I would like to appear in the #messageBox div.

This is what I thought would work....but it doesn't :(

html:

<div class="form_row">
<div class="buttonColumn">
<label><input type="checkbox" name="program[]" class="isChecked error">Check 1</label>
<label><input type="checkbox" name="program[]" class="isChecked error">Check 2</label>
<label><input type="checkbox" name="program[]" class="isChecked error">Check 3</label>
<label><input type="checkbox" name="program[]" class="isChecked error">Check 4</label>
</div>
<div id="messageBox"></div>

jQuery:

$('#custom_form').validate({
    rules: {
        "program[]": {
            required: true,
            minlength: 1,
        },
        errorPlacement: function(error, element) {
            if (element.attr("program[]") == "program[]") {
                error.appendTo('#messageBox');
            }
        },
        messages: {
            "program[]": "Please choose a program.",
        }
    });          
Esailija
  • 138,174
  • 23
  • 272
  • 326
Carey Estes
  • 1,534
  • 2
  • 31
  • 59
  • possible duplicate of [this question](http://stackoverflow.com/questions/2969381/jquery-validation-plug-in-custom-error-placement) – madfriend Jul 19 '12 at 18:49

1 Answers1

1

I think theres a problem in you if.

element.attr("program[]") == "program[]" should be element.attr("name") == "program[]"