Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
When i am in Edit mode i have a Update Button which should be enabled only when checkboxes are changed for example there are 2 records in edit mode :

Branches ||      Manage           ||       Email
ABC      ||  (CheckBox Checked)   || (CheckBox UnChecked)
PQR      ||  (CheckBox UnChecked) || (CheckBox UnChecked)

Now only if i change any of the above checkboxes then only the Update button should be enabled. If i change but again i keep the same above checks then it should again be disabled as new changed value is same as the previous value


What I have tried:

I am using jquery on each tr click but i dont know how to store values of each checkbox of each tr to compare after values changed.
Posted
Updated 25-Sep-16 20:09pm

1 solution

check this

<html>
<head title="">

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
    <script>
        var initialstate = '';
        var changedstate = '';
        $(function () {
            $('.myclass').each(function (i, elem) {
                initialstate += (elem.checked ? '1' : '0') + '-';
                changedstate += (elem.checked ? '1' : '0') + '-';
            });

            $('.myclass').on('click', function () {
                changedstate = '';
                $('.myclass').each(function (i, elem) { changedstate += (elem.checked ? '1' : '0') + '-' });
            });
           
        });
        function validate()
        {
            if (initialstate == changedstate) { alert('no changes'); }
            else
                alert('data changed!');

        }
    </script>
</head> 
<body>
    <table>
        <tr>
            <td>Branches</td>
            <td>Manage</td>
            <td>Email</td>
        </tr>
        <tr><td>ABC</td><td><input type="checkbox" checked="checked" class="myclass"></td><td><input type="checkbox" class="myclass"></td></tr>
        <tr><td>PQR</td><td><input type="checkbox" class="myclass"></td><td><input type="checkbox" class="myclass"></td></tr>
    </table>
    <button onclick="validate()">submit</button>
</body>
</html>


demo:- JSFiddle[^]
 
Share this answer
 
v2
Comments
Abrar Kazi 26-Sep-16 2:41am    
Thanks Karthik.
Karthik_Mahalingam 26-Sep-16 2:42am    
welcome Abrar
Abrar Kazi 26-Sep-16 3:01am    
Worked perfectly.
Karthik_Mahalingam 26-Sep-16 3:03am    
cool
Abrar Kazi 26-Sep-16 3:02am    
on click should be outside the $(function(){}) thats what i changed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900