Another Salesforce blog!!!

Salesforce, Apex

How to restrict the user to allow only one checkbox of each checked?


i have a two columns (approve all/reject all) how to restrict the user to allow only one checkbox of each?

Output screen
output screen

<html xmlns=”http://www.w3.org/1999/xhtml”> 
<head runat=”server”> 
    <title></title> 
    <script src=”Scripts/jquery-1.4.1.min.js” type=”text/javascript”></script> 
</head> 
<body> 
    <form id=”form1″ runat=”server”> 
    <div> 
        <table border=”1″> 
            <tr> 
                <td><input type=”checkbox” id=”C1All” />Approve All</td> 
                <td><input type=”checkbox” id=”C2All” />Reject All</td> 
            </tr> 
            <tr> 
                <td><input type=”checkbox” id=”C101″ class=”col1″ />John 0</td> 
                <td><input type=”checkbox” id=”C201″ class=”col2″ />John 0</td> 
            </tr> 
            <tr> 
                <td><input type=”checkbox” id=”C102″ class=”col1″ />John 1</td> 
                <td><input type=”checkbox” id=”C202″ class=”col2″ />John 1</td> 
            </tr> 
            <tr> 
                <td><input type=”checkbox” id=”C103″ class=”col1″ />John 2</td> 
                <td><input type=”checkbox” id=”C203″ class=”col2″ />John 2</td> 
            </tr> 
        </table> 
    </div> 
    </form> 
    <script type=”text/javascript”> 
        $(document).ready(function () { 
            $(‘#C1All’).click(function () { 
                $(‘.col1’).attr(“checked”, $(‘#C1All’).attr(“checked”)); 
                $(‘.col2’).removeAttr(“checked”); 
                $(‘#C2All’).removeAttr(“checked”); 
            }); 
 
            $(‘#C2All’).click(function () { 
                $(‘.col2’).attr(“checked”, $(‘#C2All’).attr(“checked”)); 
                $(‘.col1’).removeAttr(“checked”); 
                $(‘#C1All’).removeAttr(“checked”); 
            }); 
 
            $(‘.col1’).each(function () { 
                $(this).click(function () { 
                    var id = $(this).attr(‘id’); 
                    var coresId = id.replace(‘C1’, ‘C2’); 
                    $(‘#’ + coresId).removeAttr(“checked”); 
                    $(‘#C1All’).removeAttr(“checked”); 
                    $(‘#C2All’).removeAttr(“checked”); 
                }); 
            }); 
 
            $(‘.col2’).each(function () { 
                $(this).click(function () { 
                    var id = $(this).attr(‘id’); 
                    var coresId = id.replace(‘C2’, ‘C1’); 
                    $(‘#’ + coresId).removeAttr(“checked”); 
                    $(‘#C1All’).removeAttr(“checked”); 
                    $(‘#C2All’).removeAttr(“checked”); 
                }); 
            }); 
        }); 
    </script> 
</body>  
</html> 

Leave a Reply

Your email address will not be published. Required fields are marked *

*