.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

JavaScript to check/uncheck the header checkbox of the grid

Posted By:Maverick       Posted Date: July 21, 2011    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

JavaScript to check/uncheck the header checkbox of the grid
 

Hello All,

The javascript below will check/uncheck the header checkbox of the grid.

function CheckChanged(headerCheckBoxId, childCheckBoxId) {
    var frm = document.forms[0];
    var boolAllChecked;
    boolAllChecked = true;
    for (i = 0; i < frm.length; i++) {
        e = frm.elements[i];
        if (e.type == 'checkbox' && e.name.indexOf(childCheckBoxId) != -1) {
 
            if (e.checked == false) {
                boolAllChecked = false;
                break;
            }
        }
    }
    for (i = 0; i < frm.length; i++) {
        e = frm.elements[i];
        if (e.type == 'checkbox' && e.name.indexOf(headerCheckBoxId) != -1) {
            if (boolAllChecked == false)
                e.checked = false;
            else
                e.checked = true;
            break;
        }
    }
}

 

Hope it helps.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend