Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to store the checkbox value in an array, however, i can not use the validate rules since the name is selectList[] instead of selectList. I tried id but it seems the rule only bind to the name.

html:

<input id='sendList' type='checkbox' name='selectList[]' value='$set[ListID]'>

js rule:

  $("#selectList").validate( {
      rules: {
          selectList[]: {
              required: true,
              minlength: 1
          }
       }
   })

});

Thank you

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Why not wrap selectList[] inside quotes:

$("#selectList").validate({
    rules: {
        'selectList[]': {
            required: true,
            minlength: 1
        }
    }
});

In initializing Javascript object property names, they can be an identifier (the way you tried), a number or a string.

Working code: http://jsfiddle.net/rMgLG/

share|improve this answer
1  
Actually this is a non working answer. jQuery validate doesn't allow validation for multiple fields with the same name, so in the above answeronlthe first field with name selectList[] would be validated which doesn't help much if you trying to post an array of fields... –  jtheman Mar 12 '13 at 14:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.