tags:

views:

23

answers:

2

I have a user control

<input id="check" type="checkbox" />  
 <label>&nbsp;</label>  
<fieldset class="clearfix" id="fieldset-exception">
    <legend>Student Information</legend>
    <div class="fiveper">
        <label for="StudentID">
            Exception ID:
            <span><%=Html.EditorFor(x => x.studentid)%></span>
        </label>
        <label for="Classroom">
            Origination:
            <span><%=Html.EditorFor(model => model.Classroom)%></span>
        </label>
        <label for="Subject">
            Age:
            <span><%=Html.EditorFor(model => model.subject)%></span>
        </label>
</div>
 $('#btnAll').click(function() {
           $('#Details input[type=checkbox]').attr('checked', 'checked');
        });

I am checking all checkboxes using above code but I need to make condition here that user need to select atleast one checkbox to do something? i have other button to go other page based on this checkbox checked? can anybody tell me how to check that and how to make that condition here? Thanks thanks

+1  A: 

try the following:

if ($("#Details input[@type=checkbox][@checked]").length < 1){
     return false;
}

have your button's onclick call this method, and only submit if it doesn't return false.

derek
This is not working.its doing nothing/
kumar
see edited answer
derek
+1  A: 

try something like this

if ( $('#Details input[@type=checkbox][@checked]').length < 1 ) {
    //error
}

youll also want to implement this server-side as well.

Galen