1. Home
  2. Computing & Technology
  3. JavaScript

Alternate Analysis Quiz

3. Comment Page Scripts

Each comment page can display whatever information that you want about the preceding question and its possible answers. The only things that must go on each comment page are a small script that needs to go into the head of each comment page and a link to call the script to pass control back to the question page.

If you are wondering why the copyright on this script and those on the following pages are earlier than for the quiz script itself it is because these scripts are identical to some of the ones used by earlier quiz scripts that I have written and you can therefore create several different types of quiz for your site and share the scripts between them.

Select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called quizans.js.

You then link this code into the head of each answer page using the following code:

<script src="quizans.js"
type="text/javascript"></script>

The final step is to set up a link at the bottom of the answer page that will link to the next question. The code that you need looks like this:

<a href="javascript:quiz();">Next Question</a>

Note that this same script and link need to be placed into each comment page. The question and comment page scripts between themselves will keep track of which question or comment page to display and how many questions have been answered in what way.

Now that we have the quiz questions and intervening comment pages done, its time to set up the Analysis page that will analyse the overall results.

Quiz Head Script | Quiz Body Script | Comment Page Scripts | Analysis Head | Analysis Body
Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.