Wednesday 23 January 2013

Allow Only One Checkbox to be Checked From Group Of CheckBox In Asp.Net


Hello Everyone now I am Explaining to you that if you have group of check box in your page. your requirement is to check only one check box from the group And unchecked the other then for that i am providing one javascript function that is completed your requirement.
JAVASCRIPT CODE ARE :
 $(document).ready(function() {
        
        $('input[type=checkbox]').click(function() {
             var checked = $(this).is(':checked');  //Get Current Checked check box
             
             $('input[type=checkbox]').each(function(){
             
                    document.getElementById($(this).attr('id')).checked = false; //Make unchecked all check box
             });
             if(checked)
                 $(this).attr('checked', 'checked'); //only one checked check box
             
        });
       });

May be this small code save your time.
Thank You
Chetan Virkar

No comments:

Post a Comment