New on DHTMLGoodies.com:
DHTML Chess is now available for WordPress at WordPressChess.com.
Download drag and drop quiz script
Demo (drag capitals) | Demo (simple math quiz)
Put this into your <HEAD> section
Put this into your <BODY> section
Configuration
Set up the HTML
Boxes with questions and answers is created by using the following format:
<div id="dragScriptContainer">
<div id="questionDiv">
<div class="dragDropSmallBox" id="q1">5x1</div>
<div class="destinationBox"></div>
<div class="dragDropSmallBox" id="q2">5x2</div>
<div class="destinationBox"></div>
<div class="dragDropSmallBox" id="q3">5x3</div>
<div class="destinationBox"></div>
</div>
<div id="answerDiv">
<div class="dragDropSmallBox" id="a1">5</div>
<div class="dragDropSmallBox" id="a2">10</div>
<div class="dragDropSmallBox" id="a3">15</div>
</div>
</div>
This is a short version of the code used in the demo. You have one
<div id="questionDiv">
ss parent element of all your questions. In there you put two <DIV> tags for each question.
<div class="dragDropSmallBox" id="q1">5x1</div>
<div class="destinationBox"></div>
The first one is for the question, the second is the empty box where answers could be dragged. Create as many pairs as you have questions
<div id="answerDiv"> is used as parent element for all your answers. Create one div for each of your answers inside of this div tag.
Note that the id of the answers should match the id of the question, i.e. the numeric part. Example: The <DIV> with id "a1" is the answer to the question with id "q1". You don't have to use "q" and "a" as prefix. The important part is that you have matching numbers.
Layout
Layout is controlled by use of CSS. Look at the comments there for help
Javascript variables
You have two Javascript variables available:
var shuffleQuestions = true; /* Shuffle questions ? */
var shuffleAnswers = true; /* Shuffle answers ? */
var lockedAfterDrag = false;
- shuffleQuestions = Shuffle questions
- shuffleAnswers = Shuffle answers
- lockedAfterDrag = Lock box after it has been dragged. This means that the user will not be able to drag an answer after it has been dropped on an answer.
Javascript function
I have added an empty function to the script:
function quizIsFinished()
{
}
This function is called when everything is solved correctly. You can customize this function as you want. example: put in
alert('Finished! you did it');
Strict or loose doctype
This script works best in Internet Explorer if you use a valid doctype. You can choose between using the loose or strict doctype:
Strict doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Loose doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Insert this code at the top of your HTML file.
No one has commented this - be first!
Post your comment
Comment preview: