1. Home
  2. Computing & Technology
  3. JavaScript

Results Page Addon

Join the Discussion

Questions? Comments?

I have had several people as how they can get the name of the person who completed the quiz to display on the results page so that the person can pront out their results with it identifying who it is that achieved those results.

This can be easily achieved with both the Quizmaker 1 and Quizmaker 3 scripts simply by adding your own Javascript below the quizbody script in your page. The script code that you need is quite simple, just one if statement to run a document.write statement so that it appears only on the results page. Here is the basic coding:

if (questnum == quiz.length)
document.write('HTML for results page goes here.');

You just need to make sure that the HTML that you place into the document.write statement is properly escaped. This can be most easily achieved by using the HTML to Javascript Converter which will convert the HTML into a valid document.write statement for you.

For example to put a field on the screen for the person to enter their name when they complete a quiz you might put the following code into the body of your page:

if (questnum == quiz.length)
document.writeln('<form>Name: <input type="text" '
+ '\/><\/form>');

Now when the person completes the quiz an input field allowing them to enter their name is added under their results. They can then type in their name before printing the page. You can of course include more than one input field if you want them to enter more than just their name.

If you want to get really fancy you can hide the borders around the form fields when the page is printed by adding the following stylesheet to the page:

<style>
@media print {
input {border:0;padding:0}
}
</style>

With the border hidden the information typed in will look like it is a part of the page text instead of being input into a form.

Explore JavaScript
About.com Special Features

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

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.