title: Compare onclick action of two html button using javascript
body: <p>I have this two HTML Form buttons with an onclick action associated to each one.</p>
  
  <pre><code>&lt;input type=button name=sel value="Select all" onclick="alert('Error!');"&gt;
  &lt;input type=button  name=desel value="Deselect all" onclick="alert('Error!');"&gt;
  </code></pre>
  
  <p>Unfortunately this action changes from time to time. It can be  </p>
  
  <pre><code>onclick="";&gt;
  </code></pre>
  
  <p>or  </p>
  
  <pre><code>onclick="alert('Error!');"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>onclick="checkAll('stato_nave');"  
  </code></pre>
  
  <p>I'm trying to write some javascript code that verifies what is the function invoked and change it if needed:  </p>
  
  <pre><code>var button=document.getElementsByName('sel')[0];
  // I don't want to change it when it is empty or calls the 'checkAll' function
  if( button.getAttribute("onclick") != "checkAll('stato_nave');" &amp;&amp;
      button.getAttribute("onclick") != ""){
      //modify button
      document.getElementsByName('sel')[0].setAttribute("onclick","set(1)");
      document.getElementsByName('desel')[0].setAttribute("onclick","set(0)");
  } //set(1) and set(0) being two irrelevant function
  </code></pre>
  
  <p>Unfortunately none of this work.
  Going back some steps I noticed that  </p>
  
  <pre><code>alert( document.getElementsByName('sel')[0].onclick);
  </code></pre>
  
  <p>does not output the onclick content, as I expected, but outputs:  </p>
  
  <pre><code>function onclick(event) {
      alert("Error!");
  }
  </code></pre>
  
  <p>So i guess that the comparisons fails for this reason, I cannot compare a <code>function</code> with a <code>string</code>.<br>
  Does anyone has a guess on how to distinguish which function is associated to the <code>onclick</code> attribute?</p>