Reputation: 2140
I have a node express app using EJS.
I have a button:
<button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button>
and a script:
<script type="text/javascript">
function exportWithObjectId(objectId) {
console.log("objectID inside .ejs: " + objectId);
}
</script>
in my .ejs file but when I click there is no log. Any idea what I'm doing wrong?
Upvotes: 0
Views: 5796
Reputation: 11823
Remove document.
from your function call:
onclick="exportWithObjectId('<%= user.id %>')">
Or, replace it with window.
:
onclick="window.exportWithObjectId('<%= user.id %>')">
function exportWithObjectId(objectId) {
console.log("objectID inside .ejs: " + objectId);
alert('Just to be sure! objectID inside .ejs: ' + objectId);
}
<button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button>
Upvotes: 1