Posted By

mariraj on 06/01/11


Tagged


Versions (?)

Check all and uncheck all


 / Published in: JavaScript
 

  1. function checkAll(fmobj, checkAllId) {
  2. for (var i=0;i<fmobj.elements.length;i++) {
  3. var e = fmobj.elements[i];
  4. if ( (e.id != checkAllId) && (e.type=='checkbox') && (!e.disabled) ) {
  5. e.checked = document.getElementById(checkAllId).checked;
  6. }
  7. }
  8. }
  9. function checkCheckAll(fmobj, checkAllId ) {
  10. var TotalBoxes = 0;
  11. TotalOn = 0;
  12.  
  13. for (var i=0;i<fmobj.elements.length;i++) {
  14. var e = fmobj.elements[i];
  15. if ((e.name != checkAllId ) && (e.type=='checkbox')) {
  16. TotalBoxes++;
  17. if (e.checked) {
  18. TotalOn++;
  19. }
  20. }
  21. }
  22. if (TotalBoxes==TotalOn) {
  23. document.getElementById(checkAllId).checked=true;
  24. }
  25. else {
  26. document.getElementById(checkAllId).checked=false;
  27. }
  28. }

Report this snippet  

You need to login to post a comment.