title: Change onClick attribute with javascript
body: <p>This is my function and it should change the onClick attribute of the HTML input, but if I use</p>
  
  <pre><code>document.getElementById('buttonLED'+id).onclick = "writeLED(1,1)";
  </code></pre>
  
  <p>it does not work at all, but if I use </p>
  
  <pre><code>document.getElementById('buttonLED'+id).onclick = writeLED(1,1);
  </code></pre>
  
  <p>the function executes by itself!
  Any ideas what code do I have to use to change the onCLick attribute WITHOUT executing the function, before the button is clicked?<br>
  Here is the full function, if it matters:</p>
  
  <pre><code>function showLED(id){
      if(color == 0){
          document.getElementById('buttonLED'+id).onclick = "writeLED(1,1)";
          document.getElementById('buttonLED'+id).value="light is on";
          //document.getElementById('buttonLED'+id).disabled = false;
      }else{
          document.getElementById('buttonLED'+id).onclick = "writeLED(1,0)";
          document.getElementById('buttonLED'+id).value="light is off";
          //document.getElementById('buttonLED'+id).disabled = false;
      }
  }
  </code></pre>