I am using ejs to dynamically generate buttons, which have onclick functions which live inside a remote script tag. The remote script runs, but when the buttons are clicked, the function cannot be found.
collection:148 Uncaught ReferenceError: viewPanoscape is not defined at HTMLButtonElement.onclick
My ejs file
<body>
<tbody>
<% let c=1 %>
<% collection.forEach(function(ps){ %>
<tr>
<th scope="row"><%=c%></th>
<td><button type="button" class="btn btn-primary" onclick="viewPanoscape()">View</button></td>
<%c++%>
</tr>
</tbody>
my remote collection.js file
function viewPanoscape(e){
console.log('viewPanoscape', e);
}
window.onload = function() {
viewPanoscape("test");
}
I know the script loads as the console prints
viewPanoscape test
But when I click the button, it does not see the function. Clearly this is a scoping problem, but I don't understand how the best way to include a function that ejs can see.