1. Home
  2. Computing & Technology
  3. JavaScript

Multiple Fill in the Blanks Quiz

4. Add the Dropdowns

Join the Discussion

Questions? Comments?

All that remains to be done now for each page of your quiz is to add the form that contains the dropdown lists and the "Go" button.

Let's start by coding the form itself with the button at the bottom of the form. The code for this follows simply substitute the appropriate next page of the quiz that is to be displayed for 'next.htm'.

<form name="quiz" action="">
...
<p align="center"><input type="button" value="Go!"
onclick="test(this.form,'next.htm')" /></p>
</form>

The actual text of the quiz complete with the dropdowns goes in place of the ... in the code shown above. You can include all of the usual HTML to determine how you want the text laid out in paragraphs etc. you just replace the words that you want to test for with select boxes. For example the first line of the sample text was coded like this:

<p align="center"><b>Hey diddle diddle, the cat and the
<select name="q1">
<option value="0"></option>
<option value="0">mouse</option>
<option value="1">fiddle</option>
<option value="0">rat</option>
<option value="0">guitar</option>
</select>,<br />

The important part of this code is the values that are assigned to each of the options in the list. The correct answer should have a value of "1" while all of the other options should have a value of "0". This will provide the script with sufficient information to be able to work out if all of the blanks have been filled out correctly.

Introduction | Sample Pages | Obtain the Script | Add to Your Scripts
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.