Hi! Im new to this site so if i made a mistake in my text please say so. I need help in resolving an issue. I need to make an HTML quiz so i found this site http://www.hungrypiranha.org/make-a-website/html-quiz who at first looked like the perfect solution. The problem is that it doesnt work. I made everything written on the site. HTML and CSS work but the JS and JQ dont seem to work. Please help.
Hello @UnKn0wn27 and welcome to the forums. We would need to see your code to see where you have gone wrong.
Do you have jQuery working? An easy way to tell this is to use the following separate piece of code:
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
}
The main problem are in these 2 codes.
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/quiz-1.js"></script>
they dont respond.
Unfortunately i’m still new at HTML and JS. I never worked with jQuery. So the code you presented me is alien to me and i dont know how to use it. The site i was looking just gave a jQuery loaded with a huge code and with an assurance that it works.
Have you uploaded those two files (jquery.js and quiz-1.js) in the js folder off your root folder?
Thanks everyone for helping me! I found the solution. i had to indicate the full adress of where the .js file was located.
this is how it should have looked:
> <script type="text/javascript" src="d:/IT in MD/js/jquery.js"></script>
> <script type="text/javascript" src="d:/IT in MD/js/quiz-1.js"></script>
If you are testing it by clicking on a html file off your desktop, then yes. But if you’re running from a web server, that won’t work.
Yep, like Dave says it’s better to use relative paths which just have the path relative to the HTML file, this will probably do what you want.
<script src="js/jquery.js"></script>
<script src="js/quiz-1.js"></script>
At this point im just studying it and before i go and start to do the real thing i need to know how the basic works.
Yes it does work. Thank you! But why did it not work in the first place? why did the “type” command do?
It’s the difference between absolute and relative relations. The / instructs the website to look at the root of the site to find the files. Without the leading slash tells the website to look relative to where the html file is located
OK, the best way to describe it would be to show you like this. Say you have this file structure:
- site
- index.html
- js
- jquery.js
- quiz-1.js
- test
- index2.html
- js2
- quiz-2.js
Say your site runs off of the site folder. If running index.html (www.example.com/index.html), to get to quiz-1.js and to quiz-2.js, any of these would work.
absolute path
<script src="/js/quiz-1.js"></script>
<script src="/test/js2/quiz-2.js"></script>
relative path - because index.html is in the root, just start from there and drill down
<script src="js/quiz-1.js"></script>
<script src="test/js2/quiz-2.js"></script>
Now for index2.html (www.example.com/test/index2.html) , the absolute path stays the same because that starts off the root of the site, but the relative path is different because it’s sitting in a sub-folder under the root of the site
absolute path
<script src="/js/quiz-1.js"></script>
<script src="/test/js2/quiz-2.js"></script>
relative path - because index.html is in the test folder, it must go up a level (which is what the … does), then into the js folder for quiz-1, but only have to start from js2 to find quiz-2 since both are under the test folder.
<script src="../js/quiz-1.js"></script>
<script src="js2/quiz-2.js"></script>
Thank you! I understand now.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.