Wednesday, December 3, 2008

Javascript Snippet : Select All, None, Invert checkbox


//int mode
// mode = 0 invert selection
// mode = 1 select none
// mode = other than 0 or 1, select all
function checkChange(mode)
{
for(i=0;i<document.forms[0].elements.length;i++)
{
var ele = document.forms[0].elements[i];
if(ele.type == 'checkbox')
{
if(ele.disabled=false)
{
if(mode==0) //invert selection
ele.checked = !ele.checked;
else if(mode==1) //none
ele.checked = false;
else
ele.checked = true;
}
}
}
}

No comments:

Post a Comment

Please add your valuable comments about this post if it helped you. Thanks