Economics Network CHEER Virtual Edition

Volume 13, Issue 1, 1999

Appendix 1 of Guy Judge's article "The production and use of on-line Web quizzes for economics"
JavaScript used to create the DW quiz question

<TITLE>Simple Multiple Choice Question</TITLE>
<! BASE HREF="">
<!-- Hide script from old browsers
// This script generates a multiple-choice question on a web page.
// The HTML code is created by the script so the question, answer
// choices, and correct selection can be defined by variables.
// To adapt this script to different questions, change
// the variables directly below these comments. Do not use hard returns.
// If you want more than four choices you must also add more radio buttons.
// For more information see:
// This script may be freely used for non-commercial use as long as
// the following copyright notice remains:
// Copyright 1996 by Brian M. Tissue, all rights reserved.
var header1 = 'Multiple Choice Question'; // First page heading.
var header2 = 'Sample Question'; // Second page heading.
var question1 = 'The Durbin-Watson statistic is used to test for:';
var choice1 = 'Multicollinearity.';
var choice2 = 'Heteroskedasticity.';
var choice3 = 'Normality.';
var choice4 = 'Autocorrelation.';
var correctAnswer = 4; // Indicate the best answer with this variable.
function check(input,x) {
if (x==0) {
alert("Please make a choice.");
} else {
if (x==correctAnswer) {
input.result.value = "Correct Answer!";
} else {
input.result.value = "Please Try Again.";
function cleartext(input) {
input.result.value = ''; // Clear text field.
// Initialize answer to 0 to trap no selection.
// Generate the HTML code for the top of the web page.
document.write('<H1 ALIGN="center">',header1,'</H1>');
document.write('<H2 ALIGN="center">',header2,'</H2><HR>');
// Generate the HTML code for the radio button choices.
document.write('<FORM NAME="questn1">');
document.write('<LI><input type="radio" name="answera" onClick="answer=1">',choice1);
document.write('<LI><input type="radio" name="answera" onClick="answer=2">',choice2);
document.write('<LI><input type="radio" name="answera" onClick="answer=3">',choice3);
document.write('<LI><input type="radio" name="answera" onClick="answer=4">',choice4);
// Generate the HTML code for the buttons and response text area.
document.write('<INPUT TYPE="button" VALUE="Check Answer" onClick="check(this.form,answer)"> ');
document.write('<INPUT TYPE="reset" VALUE=" Clear " onClick="answer=0"> ');
document.write('<INPUT TYPE="text" NAME="result" SIZE="20"> ');
cleartext(document.questn1); // Clear text field on reload.
// End of script.
// End of hide script comment. -->
<!-- The script-generated HTML code will appear on the web page
as if it was placed here. -->
<LI>If there is nothing legible on your screen above these notes,
then your browser does not support JavaScript.
<LI>Netscape 2.0x does not print the script-generated portion of the web page
<LI>Please let me know if you find any bugs. Thanks.
<INPUT TYPE="button" VALUE="About MCQuest" onClick="alert('MCQuest1.html
is a demo from the forthcoming book: Using the WWW in Science and Education,
by B. M. Tissue and S. M. Dana') ">
<P>Copyright &#169; 1996 by <A HREF="">Brian
M. Tissue</A>, all rights reserved.</P>
updated 7/20/96</PRE>
Top | CHEER Home

Copyright 1989-2007