Question : Dynamic Form Element

I have the following html form and javascript that I picked up on the web. I have it customized to the point where it all works with the exception of one small part. When you select Location 3 and click on either Accounting or Management checkbox the field dynamically moves to the left and pulls up the second value like it should. However, when you select the Marketing checkbox will not function like the first two items.

See code below, can anyone help?

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
var FORM_MANAGER_CONDITION_SEPARATOR = " AND ";
var FORM_MANAGER_POSSIBILITY_SEPARATOR = " OR ";
var FORM_MANAGER_NAME_VALUE_SEPARATOR = " BEING ";
var FORM_MANAGER_DEPENDS = "DEPENDS ON ";
var FORM_MANAGER_CONFLICTS = "CONFLICTS WITH ";
var FORM_MANAGER_EMPTY = "EMPTY";

function addEvent(el, ev, f) {
  if(el.addEventListener)
    el.addEventListener(ev, f, false);
  else if(el.attachEvent) {
    var t = function() {
      f.apply(el);
    };
    addEvent.events.push({'element': el, 'event': ev, 'handler': f});
    el.attachEvent("on" + ev, t);
  } else
    el['on' + ev] = f;
}

function addEvents(els, evs, f) {
  for(var i = 0; i < els.length; ++i)
    for(var j = 0; j < evs.length; ++j)
      addEvent(els[i], evs[j], f);
}

addEvent.events = [];

if(typeof window.event !== "undefined")
  addEvent(window, "unload", function() {
      for(var i = 0, e = addEvent.events; i < e.length; ++i)
        e[i].element.detachEvent("on" + e[i].event, e[i].handler);
    }
  );

function getRadioValue(el) {
  if(!el.length) return null;
  for(var i = 0; i < el.length; ++i)
    if(el[i].checked) return el[i].value;
  return null;
}

function getSelectValue(el) {
  if(!el.tagName  || el.tagName.toLowerCase() !== "select")
    return null;
  return el.options[el.selectedIndex].value;
}

function isElementValue(el, v) {
  if(v === FORM_MANAGER_EMPTY) v = '';
  return (
    getRadioValue(el) == v ||
    getSelectValue(el) == v ||
    (
      el.tagName &&
      el.tagName.toLowerCase() !== "select" &&
      el.value == v
    )
  );
}

function setupDependencies() {
  var showEl = function() {
    this.style.display = "";
    if(this.parentNode.tagName.toLowerCase() == "label")
      this.parentNode.style.display = "";
  };
  var hideEl = function() {
    this.style.display = "none";
    if(typeof this.checked !== "undefined") this.checked = false;
    else this.value = "";
    if(this.parentNode.tagName.toLowerCase() == "label")
      this.parentNode.style.display = "none";
    this.hidden = true;
  };
  var calcDeps = function() {
    for(var i = 0, e = this.elements; i < e.length; ++i) {
      e[i].hidden = false;
      for(var j = 0, f = e[i].className.split(FORM_MANAGER_CONDITION_SEPARATOR); j < f.length; ++j)
        if(f[j].indexOf(FORM_MANAGER_DEPENDS) === 0) {
          for(var k = 0, g = f[j].substr(FORM_MANAGER_DEPENDS.length).split(FORM_MANAGER_POSSIBILITY_SEPARATOR); k < g.length; ++k)
            if(g[k].indexOf(FORM_MANAGER_NAME_VALUE_SEPARATOR) === -1) {
	      if(e[g[k]] && e[g[k]].checked) break;
            else if(k + 1 == g.length)
                e[i].hide();
            } else {
              var n = g[k].split(FORM_MANAGER_NAME_VALUE_SEPARATOR),
                v = n[1];
              n = n[0];
	      if(e[n])
	        if(isElementValue(e[n], v)) break;
	        else if(k + 1 == g.length) e[i].hide();
	    }
        } else if(f[j].indexOf(FORM_MANAGER_CONFLICTS) === 0) {
          if(f[j].indexOf(FORM_MANAGER_NAME_VALUE_SEPARATOR) === -1) {
	    if(e[f[j].substr(FORM_MANAGER_CONFLICTS.length)] && e[f[j].substr(FORM_MANAGER_CONFLICTS.length)].checked) {
              e[i].hide();
              break;
            }
          } else {
            var n = f[j].substr(FORM_MANAGER_CONFLICTS.length).split(FORM_MANAGER_NAME_VALUE_SEPARATOR),
              v = n[1];
            n = n[0];
            if(e[n]) {
              if(isElementValue(e[n], v)) {
                e[i].hide();
                break;
              }
            }
          }
        }
      if(!e[i].hidden) e[i].show();
    }
  };
  var changeHandler = function() {
    this.form.calculateDependencies();
    return true;
  };
  for(var i = 0; i < arguments.length; ++i) {
    for(var j = 0, e = window.document.forms[arguments[i]].elements; j < e.length; ++j) {
      addEvents([e[j]], ["change", "keyup", "focus", "click", "keydown"], changeHandler);
      e[j].hide = hideEl;
      e[j].show = showEl;
    }

    (e = window.document.forms[arguments[i]]).calculateDependencies = calcDeps;
    e.calculateDependencies();
  }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script src="FormManager.js">
</script>

<script type="text/javascript">
window.onload = function() {
    setupDependencies('weboptions'); //name of form(s). Seperate each with a comma (ie: 'weboptions', 'myotherform' )
  };
</script>
</head>

<body>
Please select your campus and academic discipline.

<form action="" name="weboptions">
  <p>
    <label><input type="radio" name="location" value="florida">Location 1</label><br>
    <label><input type="radio" name="location" value="michigan">Location 2</label><br>
    <label><input type="radio" name="location" value="texas">Location 3</label><br><br>
    <label style="margin-bottom: 1em; padding-bottom: 1em; border-bottom: 3px silver groove;"><input type="hidden" class="DEPENDS ON location BEING florida"></label>
    <label><input name="s1" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Accounting</label>
    <label><input name="s2" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Advertising & Marketing</label>
    <label><input name="s3" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Aftermarket Management</label>
    <label><input name="s4" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Automotive Marketing & Management</label>
    <label><input name="s5" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Economics</label>
    <label><input name="s6" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Entertainment, Sport & Promotion Management</label>      
    <label><input name="s7" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Entrepreneurship</label>
    <label><input name="s8" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Finance</label>
    <label><input name="s9" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Hotel, Restaurant & Resort Management</label>
    <label><input name="s10" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">International Business</label>
    <label><input name="s11" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Management</label>
    <label><input name="s12" type="checkbox" class="DEPENDS ON location BEING florida" id="s1">Marketing</label>      
    <label><input type="checkbox" name="accounting" class="DEPENDS ON location BEING texas AND CONFLICTS WITH management AND marketing" id="1">Accounting</label>
    <label><input type="checkbox" name="accountinga" class="DEPENDS ON location BEING texas AND DEPENDS ON accounting">Accountinga</label>
    <label><input name="management" type="checkbox" class="DEPENDS ON location BEING texas AND CONFLICTS WITH accounting AND marketing" id="2">Management</label>
    <label><input type="checkbox" name="managementa" class="DEPENDS ON location BEING texas AND DEPENDS ON management">Managementa</label>
    <label><input type="checkbox" name="marketing" class="CONFLICTS WITH management AND DEPENDS ON location BEING texas AND CONFLICTS WITH accounting">Marketing</label>
    <label><input type="checkbox" name="marketinga" class="CONFLICTS WITH management AND DEPENDS ON location BEING texas AND DEPENDS ON marketing AND CONFLICTS WITH management">Marketinga</label>
    <label><input name="s1" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Accelerated BBA/MBA Program</label>
    <label><input name="s2" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Accounting</label>
    <label><input name="s3" type="checkbox" class="DEPENDS ON location BEING michigan" id="s3">Advertising & Marketing</label>
    <label><input name="s4" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Aftermarket Management</label>
    <label><input name="s5" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Automotive Marketing & Management</label>
    <label><input name="s6" type="checkbox" class="DEPENDS ON location BEING michigan" id="s3">Economics</label>
    <label><input name="s7" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Entertainment, Sport & Promotion Management</label>
    <label><input name="s8" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Entrepreneurship</label>
    <label><input name="s9" type="checkbox" class="DEPENDS ON location BEING michigan" id="s3">Fashion Marketing & Management</label>
    <label><input name="s10" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Finance</label>
    <label><input name="s11" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Hotel, Restaurant & Resort Management</label>
    <label><input name="s12" type="checkbox" class="DEPENDS ON location BEING michigan" id="s3">International Business</label>
    <label><input name="s13" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Management</label>
    <label><input name="s14" type="checkbox" class="DEPENDS ON location BEING michigan" id="s1">Management Information Systems</label>
    <label><input name="s15" type="checkbox" class="DEPENDS ON location BEING michigan" id="s3">Marketing</label>            
  </p>
</form>
</body>
</html>

Answer : Dynamic Form Element

There you go that should sort it sorry it's taken so long it had me stumped for a while.
All the best,
Ian
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
<form action="" name="weboptions">
<p>
<label><input type="radio" name="location" value="florida">Location 1</label><br>
<label><input type="radio" name="location" value="michigan">Location 2</label><br>
<label><input type="radio" name="location" value="texas">Location 3</label><br><br>
  <label><input type="checkbox" name="accounting" class="DEPENDS ON location BEING texas AND CONFLICTS WITH management AND CONFLICTS WITH marketing" id="1">Accounting</label>
<label><input type="checkbox" name="accountinga" class="DEPENDS ON location BEING texas AND DEPENDS ON accounting">Accountinga</label>

<label><input name="management" type="checkbox" class="DEPENDS ON location BEING texas AND CONFLICTS WITH marketing AND CONFLICTS WITH accounting" id="2">Management</label>
<label><input type="checkbox" name="managementa" class="DEPENDS ON location BEING texas AND DEPENDS ON management">Managementa</label>

<label><input type="checkbox" name="marketing" class="DEPENDS ON location BEING texas AND CONFLICTS WITH accounting AND CONFLICTS WITH management">Marketing</label>
<label><input type="checkbox" name="marketinga" class="CONFLICTS WITH management AND DEPENDS ON location BEING texas AND DEPENDS ON marketing AND CONFLICTS WITH management">Marketinga</label>         
</p>
</form>
Random Solutions  
 
programming4us programming4us