Sunday, October 18, 2009

Quick way to 'check/uncheck all checkboxes'

I needed to allow my client to 'check/uncheck' all boxes in a multi-row grid. I found this very convenient code that creates a hyperlink to do simply that; add the link anywhere on the A5W page. Only thing, it checks/unchecks ALL boxes on the page, so it is only useful if you have just ONE group of checkboxes on your page.

<a href="javascript:(function(){%20function%20toggle(box){%20temp=box.onchange;%20box.onchange=null;%20box.checked=!box.checked;%20box.onchange=temp;%20}%20var%20x,k,f,j;%20x=document.forms;%20for%20(k=0;%20k<x.length;%20++k)%20{%20f=x[k];%20for%20(j=0;j<f.length;++j)%20if%20(f[j].type.toLowerCase()%20==%20%22checkbox%22)%20toggle(f[j]);%20}%20})();">Check All</a>

No comments: