title: Javascript - Onclick event happening during and only during page load
body: <p>I'm still fairly new to javascript and I'm not finding where I'm making my mistake.  The basic set up I'm working with is a set of radio buttons along with a set of check boxes. Depending on the radio button picked only a specific set of check boxes should be available the rest should be disabled/grayed out. Which check boxes are allowed for a given radio button are passed in through a php array. In my code the exclusive choices refer to the radio buttons while the extended choices refer to check boxes. My javascript and php for this functionality is as follows:</p>
  
  <pre><code>window.onload = function(){
      &lt;?php
      for($i = 0; $i &lt; count($students_information); $i++){
          foreach($exclusive_extended_array as $exclusive =&gt; $extended){
              echo "$('".$i."_exclusive_".$exclusive."').onclick = allow(".$i.",".json_encode($extended).");";
          }
      }
      ?&gt;
  }
  function allow(i, extended){
      $('[id^="'+i+'Extended"]').disabled = true;
      for (var j = 0; j &lt; extended.length; j++) {
          alert(extended[j]);
          $(i+"Extended"+extended[j]).disabled = false;
      }
  }
  </code></pre>
  
  <p>On the loaded page it appears as:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  window.onload = function(){
      $('0_exclusive_2176').onclick = allow(0,[1975]);
      $('0_exclusive_911').onclick = allow(0,[]);
      $('0_exclusive_795').onclick = allow(0,[1973,1975]);
  }
  function allow(i, extended){
      $('[id^="'+i+'Extended"]').disabled = true;
      for (var j = 0; j &lt; extended.length; j++) {
          alert(extended[j]);
          $(i+"Extended"+extended[j]).disabled = false;
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Unfortunately, what the code ends up doing is running the script when the page loads rather than when one of the radio buttons is checked. I don't think it's an issue with the names of the elements (though I do realize the naming style is not consistent, however, I don't have full control over that). I'm assuming it's just me making a simple mistake in the code and I still don't have enough experience with javascript to catch it yet. Anyone see what I'm doing wrong?</p>
  
  <p>Thank you for your time!</p>