last day (15 days later) » 

11:37 PM
0
Q: Django can't find .js file

TK-421My directory structure looks like this: I link to my site.js file in base.html like this: {% load staticfiles %} <html> <head> <script type="text/javascript" src="{% static 'site.js' %}"</script> </head> </html> But when I try to call a function from my JS file from a templ...

 
The input has type="submit" is it in a form?
 
Yes, it is in a form.
 
Is your issue that the the form is being submitted rather than your function being called?
 
No, I can handle that without a problem, the issue is that the function isn't being found, which I assume is due to the fact that the JS file isn't being found. My CSS file is found perfectly fine, and it's in the exact same place as the JS file, so this makes no sense to me.
 
You assume the js file isn't being found, have you opened your browser console and seen a 404?
 
11:37 PM
The console says "deleteGame" is not a function.
 
What does the network tab say?
 
It would appear that the site.js file is included.
 
I think the issue might just be malformed html, the script tag is missing the closing > MIGHT BE THE ISSUE
sorry for the caps
 
This is the copy and pasted HTML from the script tag:

<script type="text/javascript" src="{% static 'site.js' %}"></script>
 
The only think I can think of is that there is something going on in your js file
Is the function defined inside the global scope?
 
11:49 PM
The file only contains one function, which is the one that doesn't work. The file looks like this:
// Select 'true' for Delete Current Game bool
function deleteGame() {
document.getElementById("deleteGameBool").value = true;
}
 
and when you open the file in your browser, that is what you see?
it's not cached?
If you are using the django staticfiles app, have you run the collectstatic management command?
 
It is cached and looks exactly the same in the browser
I am in development, I have not gotten to deployment yet.
 
Wait, the console says that deleteGame is not a function, if you type deleteGame into the console what does your browser say that "deleteGame" is?
 
I'm not sure what you mean
How do I type deleteGame into the console?
 
If your js had not been loaded you would get a different error
 
11:58 PM
I can barely even see the error because it disappears after a split second since my function is inside a form.
I've tried adding the function to a button outside of the form, but nothing happens at all when I click it.
 
change the onclick to "deleteGame(); return false;" to prevent the form submitting
 

  last day (15 days later) »