I am simply trying to show a message box on screen.
This is the HTML for the button that invokes the message box—
<button onclick="myFunction()">Try it</button>
This is the relevant javascript function code–
function myFunction()
{
alert("Hello World!");
}
The javascript function is stored at js/fetchdetails.js (path relative to the HTML file).
I have included the JS file in the HTML file using the following code in the head section–
<script src="js/fetchdetails.js"></script>
What am I doing wrong here?
There’s nothing wrong in the code you’ve posted; the error is somewhere else.
Either your
fetchdetails.jsis not being loaded, or some error in javascript not shown here causes your script to stop executing.Use your browser’s inspection tool to look for any error messages, and to verify that the file has loaded correctly (there’s usually a “Net” tab for that).