title: Executing a function onclick via ejs template
body: <p>I am making a web application using node.js. I'm handling the server side via Express and using ejs templates to serve up the webpages. My issue is that I have a function  in my index.js file and it is referenced in my ejs file in the button's onclick event. Currently I'm only logging a statement in the console to make sure it works. Now every time I restart the server and open up my home route, I see the message logged into the console but when I click the actual button, nothing happens. The fuction executes on the server start/restart but not when the button is clicked. I've tried writing the function entirely inside the ejs page using the correct ejs syntax and tags. Every time the same issue occurs; the function executes when the homepage is refreshed and logs the message in the console but nothing happens when the button is clicked.</p>
  <p>I'm guessing since I'm calling the function in the res.render route, it gets executed once the page is rendered. How do I go about making changes so that the function executes once the button is clicked?</p>
  <p>Here's the function for the button (inside <strong>index.js</strong>):</p>
  <pre><code>function clicker() {
    console.log(&quot;Button Working!&quot;);
  };
  </code></pre>
  <p>Here's the <strong>index.js</strong> code that handles the route for this function:</p>
  <pre><code>app.get(&quot;/&quot;, (req, res) =&gt; {
    res.render(&quot;home&quot;, {
      x: clicker()
    });
  });
  </code></pre>
  <p>Button Tag inside my <strong>home.ejs:</strong></p>
  <pre><code>&lt;button class = 'btn btn-primary' onclick = &quot;&lt;%=x%&gt;&quot;&gt;Click Me!&lt;/button&gt;
  </code></pre>
  <p>Console view:</p>
  <p><a href="https://i.stack.imgur.com/Om3lY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Om3lY.png" alt="Message shows up when the homepage is loaded/refreshed." /></a></p>