MayNotBe
MayNotBe

Reputation: 2140

Bootstrap button onclick not working

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

Answers (1)

Uzbekjon
Uzbekjon

Reputation: 11823

Remove document. from your function call:

onclick="exportWithObjectId('<%= user.id %>')">

Or, replace it with window.:

onclick="window.exportWithObjectId('<%= user.id %>')">

Example:

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

Related Questions