I want to execute a nodejs function in ejs template, the idea is when I click the button the function should be executed and the result should appear in the placeholder. As shown in the screen shoot below:
I have embeded the function to the ejs file like below:
router.get('/lottery/generator', (req, res) => {
res
.status(200)
.render('generator', { generator: kaikkiController.uniqueRandomNumbers });
})
And then I tried to excute the function by click the button as shown in the generator.ejs
file below:
<%- include('partials/header') -%>
<div class="container mt-5 w-50">
<h2 class="mb-4">Generator</h2>
<div id="true">RESULT SHOULD BE HERE</div>
<button
id="submit"
onclick="<%= generator%>"
class="btn btn-danger btn-block mt-3"
>
Generate
</button>
</div>
<%- include('partials/footer') -%>
But I couldn’t get the result of the excution. Any suggestion please?