Working: Initially, When quiz is inside index.html, everything works fine. I could access the quiz section by using #quiz, as shown below:
<div data-role="content">
<ul data-role="listview">
<li><a href="#quiz">Quiz Page</a></li>
<li><a href="#page3">Page Three</a></li>
</ul>
Then, I decided to make the quiz as a standalone html page. So, I cut the javascripts from index.html for scoring and question hide-show script, as well as quiz questions and paste it into quiz.html page. In order to access this quiz page, I modify the link in index.html as
<div data-role="content">
<ul data-role="listview">
<li><a href="quiz.html">Quiz Page</a></li>
<li><a href="#page3">Page Three</a></li>
</ul>
</div>
The scoring script is as below (simplified):
<script type="text/javascript"> //scoring script
function getScore(form){
//score counting algorithm
score = Math.round(score/AnswersAndObjects.length*100);
form.percentage.value = score + "%";
}
</script>
And the question hide-show script is as below (simplified):
<script type="text/javascript"> //quiz question hide-show script
$(document).ready(function () {
var currentQuestion=0;
var totalQuestions=$('.questions').length;
$questions = $('.questions');
//show the first question
//when users click on the "Next question button...
$('#next').click(function(){
$($questions.get(currentQuestion)).fadeOut(function(){ //hide the current question
//go to next question
if(currentQuestion == totalQuestions){ //if no more question
//do hide and show div class
}else{
//else display the current question
}
});
});
});
</script>
For your information, each question is wrapped as
<div class="questions">Question here</div>
The problem: When I access quiz.html from index.html, nothing is working. Scores could not be calculated and show() hide() are not working. However, if I access quiz.html directly, everything is working fine. I am suspecting that javascript is not loading when quiz.html is accessed from index.html. However, I already included
$(document).ready(function () {
in quiz.html.
May I know how can I make this work?