views:

45

answers:

0

Hi guys,

How do I trigger validation (using the validate plugin) from a group of checkboxes using jQuery, without using the name of the checkbox (this is controlled by the serverside app)? The validation message is currently displayed only once -(when you press the submit button) and I need it to be fired everytime a checkbox gets triggered. I've got a maximum of 3 checkboxes that can be checked at any one time - that's when the error message should be displayed.

$(".chckBoxInput").rules("add", {  
    maxlength:3,  
    required:true,  
    "separateFunction": {   
        required:true  
    }  
    required: function(){  
        var checkboxes = $("input[@class=chckBoxInput]:checked");  
        if (checkboxes.length == 0 || checkboxes.length > 3) { 
        return false;  
        } else {  
        return true;   
        }  

    }
    messages:{
        required:"Please choose 3 to download"
    }

}

Any help would be really appreciated - cheers, Matt