Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- function addEvent(element, eventName, handler) {
- if (element.addEventListener) {
- element.addEventListener(eventName, handler, false);
- } else {
- element.attachEvent("on" + eventName, handler);
- }
- }
- function loadEvents() {
- for (var i=2; i<=numOptions; i++) {
- var thisCheckBox = document.getElementById('schoolStatuses_'+i);
- if (thisCheckBox)
- addEvent(thisCheckBox,'click', unCheckOpen);
- }
- var openBox = document.getElementById('schoolStatuses_1');
- addEvent(openBox, 'click', unCheckOthers);
- }
- function unCheckOpen(e) {
- var allUnchecked = 1;
- for (var i=2; i<=numOptions; i++) {
- var thisCheckBox = document.getElementById('schoolStatuses_'+i);
- if (thisCheckBox)
- if (thisCheckBox.checked) allUnchecked = 0;
- }
- var openBox = document.getElementById('schoolStatuses_1');
- if (allUnchecked) {
- checkBox(openBox);
- } else {
- unCheckBox(openBox);
- }
- }
- function checkBox(checkBoxItem) {
- checkBoxItem.checked = true;
- }
- function unCheckBox(checkBoxItem) {
- checkBoxItem.checked = false;
- }
- function unCheckOthers(e) {
- for (var i=2; i<=numOptions; i++) {
- var thisCheckBox = document.getElementById('schoolStatuses_'+i);
- if (thisCheckBox)
- unCheckBox(thisCheckBox);
- }
- }
- <body onload="loadEvents()">
Add Comment
Please, Sign In to add comment