This function is not being triggered, however if i include this function within the html file itself under a script tag it is being triggered. I dont want to do it this way as i have alot of other functions which i also need to access, and i feel that by taking this approach it would make my code really unorganised.
The reason is 99% the js file is not being found because the path is incorrect so double check it, As you’ve written this, the js is not in the same folder as the html file, which might be correct. You’re using a relative path to the js file. This means your html structure is assumed to be something like this (assuming the page calling this is in the root of your webserver, and is
src
js
commands.js
wwwroot
index.html
The easiest way would be to use the absolute path to the js file from the root, something like this. If your JS file can be found at www.example.com/src/js.commands.js, then use
it was in a JS folder, but what i’ve done now is move the commands.js file into the same folder as the index.html file and its still not triggering the function. I honestly have no idea what I’m doing wrong. I’ll post a picture of the folder structure.
You’ve got conflicting behavior in your javascript. Your onclick method is adding an onclick event listener. No wonder it’s not working (how it works inline, dunno…)