Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Check /uncheck all check boxes in MVC view

i have two row checkboX.each row first line i check\uncheck,it affects first or second line

my fiddle----http://jsfiddle.net/fA2w5/128/[^]



XML
<input type="checkbox" name="Test1" onclick="SetAllCheckBoxes(this)"/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</br>
<input type="checkbox" name="Test2" onclick="CheckBox(this)"/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />





C#
function SetAllCheckBoxes(obj) {
        var c = new Array();
        c = document.getElementsByTagName('input');
        for (var i = 0; i < c.length; i++) {
            if (c[i].type == 'checkbox') {
                c[i].checked = obj.checked;
            }
        }
    }


function CheckBox(obja) {
        var d = new Array();
        d = document.getElementsByTagName('input');
        for (var i = 0; i < d.length; i++) {
            if (d[i].type == 'checkbox') {
                d[i].checked = obja.checked;
            }
        }
    }




http://jsfiddle.net/fA2w5/128/[^]
Posted
Updated 20-Aug-15 23:37pm
v4

Hi, I edited your jsfiddle, not sure if that is exactly what you need, but I hope it will help.

http://jsfiddle.net/5L7q4dsc/[^]

check/uncheck:

http://jsfiddle.net/mcptsuto/[^]
 
Share this answer
 
v2
Comments
Member 10918596 21-Aug-15 7:37am    
ok fine it works only check condtion.i need uncheck also.
Member 10918596 21-Aug-15 7:37am    
please update uncheck
xszaboj 21-Aug-15 7:43am    
no problem and what exactly is the condition? when I click first-row check all and when I click first-row again uncheck?
Member 10918596 21-Aug-15 7:46am    
yes yes.
Member 10918596 21-Aug-15 7:56am    
thank u xszaboj...
Edit: I pasted an updated solution but saw this was down-voted so someone else can help :)
 
Share this answer
 
v3
Comments
Member 10918596 21-Aug-15 7:04am    
hi i need to check/uncheck each row diffent.

when i check first row ,i affects only in first rows all checkbox not at all second row checkboxes.
when i check second row ,i affects only in second rows all checkbox not at all first row checkboxes.

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