Jesper Posted October 23, 2008 Share Posted October 23, 2008 Hey everyone, for some reason my very basic javascript code is not working. The code I'm using is: <html> <head> <script type="text/javascript" language="javascript" src="test.js"> </script> </head> <body> </body> </html> in the file test.html. In the file test.js I have: document.write("testing"); I suppose this should work, but strangely enough, it doesn't. When I just use the document.write inside the script tag and remove the src part, it does work. Does anyone know what could be the cause (I'm possibily missing something very obvious). Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/ Share on other sites More sharing options...
F1Fan Posted October 23, 2008 Share Posted October 23, 2008 Is your test.js file in the same directory as your HTML file? Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673187 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 Well, you are executing that code within the head of your document. If you view the rendered source code you will probably see it there. If you made it into a function and then called the function from within the body it will probably be visible. Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673194 Share on other sites More sharing options...
Jesper Posted October 24, 2008 Author Share Posted October 24, 2008 @ F1Fan Yep, they are both in the same folder. @ CroNiX I already tried that, and it yielded nothing, even no javascript errors. Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673500 Share on other sites More sharing options...
dropfaith Posted October 24, 2008 Share Posted October 24, 2008 <script type="text/javascript" src="test.js"></script> Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673568 Share on other sites More sharing options...
Jesper Posted October 24, 2008 Author Share Posted October 24, 2008 Okay, for some reason, when I re-tested it today, it suddenly worked. Must have been a temporary problem with my computer, altough that is very strange. EDIT: @ Dropfaith What is the big difference between your and my code? Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673569 Share on other sites More sharing options...
F1Fan Posted October 24, 2008 Share Posted October 24, 2008 DropFaith's code left out the language="javascript" part. If restarting your computer fixed it, it was probably a cache issue. Also, when making changes to your test.js, you'll want to refresh it. Open it in a different tab and refresh it before refreshing your main page. That will ensure that you're using the new code. Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673716 Share on other sites More sharing options...
dropfaith Posted October 24, 2008 Share Posted October 24, 2008 weird i just yanked the code from a website i made that uses the js file i should fix the lanquage thing Quote Link to comment https://forums.phpfreaks.com/topic/129850-strange-simple-problem/#findComment-673721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.