I'm trying to send part of html code generated by server. The code is shown in modal window and everything works except javascript.
I have created small example. The code I'm sending from server (inserted directly into modal body):
<div class="container-fluid">
<div class="row row-cols-1 row-cols-lg-2 g-4">
<div class="col">
<div class="card h-100">
<div class="card-body">
<button class="btn btn-primary" type="button" id="MesuringDevicesButton" title="Test" onclick="addDevice()"><span class="material-icons-outlined">add</span></button>
<script type="text/javascript" src="/sls/layouts/measuringdevices_v1.js"></script>
</div>
</div>
</div>
</div>
</div>
content of javascript file:
function addDevice(){
console.log("MeasuringDevices button onclick method.");
}
The problem is, that console writes me error:
109:1 Uncaught ReferenceError: addDevice is not defined at HTMLButtonElement.onclick (109:1:1)
when I load the JS file in page (and not sending the <script> part from server) it works...
Do you know what I'm doing wrong?
Many thanks.