JavaScript : Creating a Random Quiz
Contents ]
Dr Benton

Setting Up the Form

Our quiz is essentially based on a form made up of three drop-down lists offering multiple choice answers and a button to submit the answers to the validation process.

 9: <FORM NAME="jeu">
10:     <TABLE>
11:       <TR>
12:         <TD WIDTH="170" HEIGHT="120">
13:           <CENTER>
14:             <IMG SRC="0.jpg" NAME="Vignt1"><BR>
15:                 <SELECT NAME="Select1" WIDTH="160" BORDER="0">
16:                    <OPTION>***
17:                    <OPTION>***
18:                    <OPTION>***
19:                 </SELECT>
20:                 </CENTER></TD>
[...]
37: </TR>
38:
39: </TABLE>
40: <BR>
41: <INPUT TYPE="button" VALUE="Submit">
42: </FORM>

We have now created a form named game enclosing a table with three cells.

Each of the cells contains an image (lines 14, 22 and 30) the name of which must begin with VigntX, where X represents the question number. The image name is essential as it is used later on to display the images according to the randomly drawn questions.

The pattern is the same for the drop-down lists (lines 15, 23 and 31). Each of them is called SelectX where X represents the question number. And each has to suggest three possible answers chosen at random by the JavaScript function. For now, we filled them in with the characters *** (lines 16 to 18 for the first question).

Now that we have our form, let's see how questions and answers can be generated at random.



  1   2   3   4   5   6