JavaScript : Creating a Random Quiz
Contents ]
Dr Benton

Displaying the Answers

Once the choices are pulled out, they have to be displayed in the form.

76: document.Vignt1.src="dossier_images/" + Vignts[Quest[0]]
77: document.Vignt2.src="dossier_images/" + Vignts[Quest[1]]
78: document.Vignt3.src="dossier_images/" + Vignts[Quest[2]]
[...]
82: var option0 = new Option(Choix1[Quest[0]])
83: document.jeu.Select1.options[0] = option0
84: var option0 = new Option(Choix2[Quest[0]])
85: document.jeu.Select1.options[1] = option0
86: var option0 = new Option(Choix3[Quest[0]])
87: document.jeu.Select1.options[2] = option0

In lines 76 to 78, we dynamically update the images by modifying their src attribute. We assume that they are stored in the folder dossier_images. Don't forget to change it if necessary in accordance with your path.

In lines 82 and 101, we filled in the lists. Here we need to create an object of type Option, the only one accepted by selection lists. This is what we do in line 82. The object label is the value of Choix1[Quest[0]], i.e. the first possible answer to the first question.



  1   2   3   4   5   6