title: SharePoint 2013 JavaScript OnClick event
body: <p>On our SharePoint 2013 page we have a button which runs an <code>EXE</code></p>
  
  <blockquote>
    <p>I want to generate a <code>JS Alert</code> when the button is clicked so that users know to click RUN</p>
  </blockquote>
  
  <p>The buttons are being generated by a <code>Content Search Web Part</code> which is reading from a list with a <code>Title</code> and <code>URL</code> field.</p>
  
  <p>For the <code>EXE</code> my url is this: <code>file:///S:/Web/EmailSignature_WPF/EmailSignature_WPF.exe</code></p>
  
  <p>I tried to embed the <code>JavaScript</code> inline using code such as: <code>javascript:open('file:///S:/Web/EmailSignature_WPF/EmailSignature_WPF.exe')</code> or more basically: <code>JavaScript:alert('TEST');</code></p>
  
  <p>But <code>SharePoint</code> is giving me an "Invalid URL" message when I try to embed <code>JS</code> in this manner.</p>
  
  <p>I have instead now moved to a <code>Script Editor Web Part</code> and am trying to add the <code>Alert</code> to the <code>OnClick</code> event of my button but this is where I am stuck.</p>
  
  <p>My <code>Script Editor</code> code:</p>
  
  <pre><code>&lt;script style="javascript;"&gt;
  var img = document.getElementById('ctl00_ctl40_g_a225dbb9_1900_49f2_afe2_ab6f5bf77adf_csr4_pictureOnTop_line1');
  img.onclick="javascript:alert('event has been triggered')";&lt;/script&gt;
  </code></pre>
  
  <p>Here is an image of the IE Debug screen which is how I'm pulling the <code>ID</code>.  This <code>H2</code> element is wrapped in an <code>HREF</code> which is wrapped in two <code>DIV</code> tags which make up an <code>LI</code></p>
  
  <p><a href="https://i.stack.imgur.com/F2kGU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F2kGU.jpg" alt="SharePoint List Item ID"></a></p>
  
  <p>With the above snippet IE Debug is giving me this error message: 
  <code>Unable to set property 'onclick' of undefined or null reference</code></p>
  
  <p>I am hoping that this is as simple as misplaced quotations, or assigning the <code>OnClick</code> event to the wrong element, but I'm spinning my wheels. Any help appreciated and I'm happy to clarify</p>