Posted By

luman on 08/06/06


Tagged

checkbox


Versions (?)

Who likes this?

25 people have marked this snippet as a favorite

xhtmled
Navegante
meth
postNuKe
damarev
hxseven
Phoenix
fael
vali29
visuallyspun
SpinZ
Wizzle
cidibee
leitmotiv
hans
fnl
ckayra
davidsi
kele5240
bobbym245
seanpowell
lfcortes
guo3823538
ApeWare
thegreatredfox


toggle_checkboxes


 / Published in: JavaScript
 

URL: http://codedump.jonasjohn.de/snippets/toggle_checkboxes.htm

Snippet: toggle checkboxes Desc: A short javascript function to toggle checkboxes Example: Author: Jonas

  1. <script type="text/javascript">
  2.  
  3. function toggle_checkboxes(id) {
  4. if (!document.getElementById){ return; }
  5. if (!document.getElementsByTagName){ return; }
  6. var inputs = document.getElementById(id).getElementsByTagName("input");
  7. for(var x=0; x < inputs.length; x++) {
  8. if (inputs[x].type == 'checkbox'){
  9. inputs[x].checked = !inputs[x].checked;
  10. }
  11. }
  12. }
  13.  
  14. </script>
  15.  
  16. <div id="parent_box">
  17.  
  18. <input type="checkbox" name="foo" value="1" /> 1<br/>
  19. <input type="checkbox" name="foo" value="2" checked="checked" /> 2<br/>
  20. <input type="checkbox" name="foo" value="3" checked="checked" /> 3<br/>
  21.  
  22. <br/>
  23. <input type="button" value="Toggle checkboxes"
  24. onclick="toggle_checkboxes('parent_box')" />
  25.  
  26. </div>

Report this snippet  

You need to login to post a comment.