We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

scriptmakingcom on 09/14/07


Tagged

javascript check checkboxes uncheck


Versions (?)


Who likes this?

6 people have marked this snippet as a favorite

jonhenshaw
luman
vali29
SpinZ
leitmotiv
korzhik


Check or Uncheck all checkboxes on a form


Published in: JavaScript 


URL: http://www.somacon.com/p117.php

  1. function SetAllCheckBoxes(FormName, FieldName, CheckValue)
  2. {
  3. if(!document.forms[FormName])
  4. return;
  5. var objCheckBoxes = document.forms[FormName].elements[FieldName];
  6. if(!objCheckBoxes)
  7. return;
  8. var countCheckBoxes = objCheckBoxes.length;
  9. if(!countCheckBoxes)
  10. objCheckBoxes.checked = CheckValue;
  11. else
  12. // set the check value for all check boxes
  13. for(var i = 0; i < countCheckBoxes; i++)
  14. objCheckBoxes[i].checked = CheckValue;
  15. }

Report this snippet 

You need to login to post a comment.