Issue
I want to use Javascript file in my Django project. But somehow I can't figure out how to import it into my html file. I tried to add it same way as I did my css file but it doesn't work. On load it shows always the same error : "Uncaught ReferenceError: fun1 is not defined at onload".
Project structure:
Js file, coding.js:
function fun1(){ alert("It works!") }
Html file, index.html:
<script src="{% static '/js/coding.js' %}"></script>
and as I mentioned, the css file, the line above, works just fine:
<link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}"/>
Adding type: text/javascript
doesn't fix it.
Solution
Solved!
Somehow the .js file is not loaded when calling the function in <body onload="function()">
I wrote the function in html tag <script>
and it's working fine.
However if I call different function in different part of html like in select onchange it normally takes it from the .js file
Thanks for help.
Answered By - MildyS
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.