Guest User

Untitled

a guest
Jul 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. var numOptions = 50; //the highest numbered checkbox field id after the "_"; #1 is reserved for "open". You **Should** be able to skip numbers and be ok
  2.  
  3. function addEvent(element, eventName, handler) {
  4.  
  5. if (element.addEventListener) {
  6. element.addEventListener(eventName, handler, false);
  7. } else {
  8. element.attachEvent("on" + eventName, handler);
  9. }
  10. }
  11.  
  12. function loadEvents() {
  13. for (var i=2; i<=numOptions; i++) {
  14. var thisCheckBox = document.getElementById('schoolStatuses_'+i);
  15. if (thisCheckBox)
  16. addEvent(thisCheckBox,'click', unCheckOpen);
  17. }
  18. var openBox = document.getElementById('schoolStatuses_1');
  19. addEvent(openBox, 'click', unCheckOthers);
  20. }
  21.  
  22. function unCheckOpen(e) {
  23. var allUnchecked = 1;
  24. for (var i=2; i<=numOptions; i++) {
  25. var thisCheckBox = document.getElementById('schoolStatuses_'+i);
  26. if (thisCheckBox)
  27. if (thisCheckBox.checked) allUnchecked = 0;
  28. }
  29.  
  30. var openBox = document.getElementById('schoolStatuses_1');
  31. if (allUnchecked) {
  32. checkBox(openBox);
  33. } else {
  34. unCheckBox(openBox);
  35. }
  36. }
  37.  
  38. function checkBox(checkBoxItem) {
  39. checkBoxItem.checked = true;
  40. }
  41.  
  42. function unCheckBox(checkBoxItem) {
  43. checkBoxItem.checked = false;
  44. }
  45.  
  46. function unCheckOthers(e) {
  47. for (var i=2; i<=numOptions; i++) {
  48. var thisCheckBox = document.getElementById('schoolStatuses_'+i);
  49. if (thisCheckBox)
  50. unCheckBox(thisCheckBox);
  51. }
  52. }
  53.  
  54. <body onload="loadEvents()">
Add Comment
Please, Sign In to add comment