lundi 1 juin 2015

how to validate a form for checkbox

I am trying to validate my checkboxes to ensure that a user clicks at least one checkbox. I am getting checkbox Names from the database. Can anyone solve this please.

$(function(){
    $("#userFrm").validate({
        rules: {
            Item1: {
                required: true,
            },
        },
        messages: {
            Item1: "Check atleast one box",
        }
    });
}

<form class="form-horizontal" action="" method="post" name="groupFrm" id="groupFrm">
    <div class="control-group">
        <label class="control-label">    
            Access Permission
            <span class="error">*</span>    
        </label>
        <div class="controls">
            <div class="text-group">
                {section name=source loop=$source}
                    <input type="checkbox" name="option1[]" id="Item1" class="first" {if in_array($source[source].id,$permission_user,true)} checked="checked"{/if} value="{$source[source].id}"  />
                    {$source[source].mod_name}
                {/section}  
            </div>
        </div>
    </div>
    <div class="form-actions">
        <input type="submit" name="edit_permission" id="edit_permission" value="Update" class="btn btn-success " onclick="validate()">
    </div>
</form>             




Aucun commentaire:

Enregistrer un commentaire