Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HTML doesn't load JS files

i try to make a simple website with external js and css files.

HTML:

<html>


<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <script src="../js/main.js"></script>
  <title> John Doe </title>
</head>

<body>

  <div>
    <p>Landing Page in Progress</p>
    <button onclick="clickAlert()">Test</button>
  </div>

</body>

</html>

JS:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function clickAlert() {
    alert("Test")
}

Folder structure:

folder_structure

But when i click the button i get the error "clickAlert is not defined".
Everything is hosted on an Webserver running Ubuntu/Apache.
I know that for this simple function i wouldn’t need an external file but i want to expand the site more.
Thanks for every help!

>Solution :

You should put the js folder in the static folder then put the src as "js/main.js". If the javascript is not included in the static folder, the server doesn’t know to put those files on the server.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading