I have am doing an app in Express with EJS and so far it was easy in respect with EJS.
My issue is that I am trying to call a function with the onclick
event handler.
I want to call the function
function click() {
console.log("You have clicked")
}
in controller I have the endpoint
exports.getPortfolioOnDue = async (req, res, next) => {
let data, click;
try {
data = await listBlobs(matchExp, containerClient, res)
} catch (error) {
res.send(error)
}
res.render('portfoliodue', { isAuthenticated: req.session.isAuthenticated, configured: isConfigured(req), data: data, click: click });
}
in the EJS file I have:
<table class="table table-striped">
<thead class="thead-light">
<tr>
<th scope="col">#</th>
<th scope="col">List of reports</th>
<th scope="col">Get item</th>
</tr>
</thead>
<% for(let i=0; i < data.length; i++) { %>
<tr>
<th scope="row"><%= i + 1 %></th>
<td><%= data[i] %></td>
<td><button type="button" class="btn btn-outline-warning btn-sm" onclick="<%= click %>">Download</button></td>
</tr>
<% } %>
</table>
I mention that the loop, retrieve data an maps it correctly.
the event handler onclick
should evaluate the expression <%= click %>
, but it doesn't.
Please help me, this should be easy and supposedly not losing time with it.
Thank you!