Quiz script - Drag and drop to columns

Demo

Bookmark and Share

Licensing

This script is distributed under the LGPL open source license.
Commercial licenses are also available. Some of these licenses also includes personal e-mail support for up to 1 year.

Put this into your <HEAD> section

Put this into your <BODY> section

Download arrow

To download the arrow used in this script, right click on it below.

Choose "Save target As" and put it in a sub folder called "images".

Configuration

Items in the left side box

The draggable items are <LI> created by the following syntax:

<ul id="allItems">
  <li id="node1" groupId="box2">Oslo</li>
  <li id="node2" groupId="box7">Paris</li>
  <li id="node3" groupId="box3">London</li>
  <li id="node4" groupId="box5">Beijing</li>
  <li id="node5" groupId="box4">Washington</li>
  <li id="node6" groupId="box6">Canberra</li>
  <li id="node18" groupId="box1">Rome</li>
  
  <li id="node7" groupId="box2">Geiranger fjord</li>
  <li id="node8" groupId="box7">Notre Dame</li>
  <li id="node9" groupId="box3">Big Ben</li>
  <li id="node10" groupId="box5">The forbidden city</li>
  <li id="node11" groupId="box6">Queensland</li>
  <li id="node19" groupId="box1">Vatican city</li>
  <li id="node21" groupId="box4">Mississippi</li>
  
  <li id="node12" groupId="box2">Frithjof Nansen</li>
  <li id="node13" groupId="box7">Napoleon Bonaparte</li>
  <li id="node14" groupId="box3">Winston Churchill</li>
  <li id="node15" groupId="box5">Mao</li>
  <li id="node16" groupId="box4">Britney Spears</li>
  <li id="node17" groupId="box6">Ned Kelly</li>
  <li id="node20" groupId="box1">Galileo Galilei</li>
</ul>

You create one <LI> for each draggable node. Put it inside the <ul id="allItems"> tag. It's important that you set the groupId attribute. The value of this attribute must match the "id" of the box where it belongs. For example: Oslo has groupId = "box2". If you like a the code below, you will see that the <UL> right below Oslo have id="box2". I.e. Oslo belongs to the box Norway.

Boxes in right side column

The boxes in the right side columns are created by use of plain HTML. Here's how it is done in this demo:

<div id="dhtmlgoodies_mainContainer">
  <!-- ONE <UL> for each "room" -->
  <div>
    <p>Italy</p>
    <ul id="box1">
    </ul>
  </div>
  <div>    
    <p>Norway</p>
    <ul id="box2"></ul>
  </div>
  <div>
    <p>United Kingdom</p>
    <ul id="box3">
    </ul>
  </div>
  <div>
    <p>United States</p>
    <ul id="box4"></ul>
  </div>
  <div>  
    <p>China</p>
    <ul id="box5">
    </ul>
  </div>
  <div>  
    <p>Australia</p>
    <ul id="box6">
    </ul>
  </div>
  <div>  
    <p>France</p>
    <ul id="box7">
    </ul>
  </div>
</div>

As you can see, there is one <DIV> followed by a <UL> for each column box.

Javascript variables

You have some Javascript variables available which you could use to customize the script:

var boxSizeArray = [3,3,3,3,3,3,3];; // Array indicating how many items there is room for in the right column ULs

var arrow_offsetX = -5; // Offset X - position of small arrow
var arrow_offsetY = 0; // Offset Y - position of small arrow

var arrow_offsetX_firefox = -6; // Firefox - offset X small arrow
var arrow_offsetY_firefox = -13; // Firefox - offset Y small arrow

var initShuffleItems = true; // Shuffle items before staring

var indicateDestionationByUseOfArrow = false;
var lockedAfterDrag = false;

  • boxSizeArray = An array indicating max number of items("students") in the small boxes on the right side.
  • arrow_offsetX = Horizontal offset of small arrow - You may have to adjust this value to get the small arrow positioned correctly
  • arrow_offsetY = Vertical offset of small arrow
  • arrow_offsetX_firefox and arrow_offsetY_firefox = Same as above, but for Firefox.
  • initShuffleItems = The left side items will be shuffled when the script loads.
  • indicateDestionationByUseOfArrow = Indicate where objects will be dropped with an arrow. If you set this variable to false, it will use a rectangle instead.
  • 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

The Javascript function called everythingIsCorrect is executed when all the nodes has been moved the the correct column. You can modify this function as you need.

Layout

The layout is controlled by use of CSS. Look at the comments there for help.

Use a strict or loose doctype

For best results, use a valid doctype. You can either choose the strict doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
or a loose doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The doctype tag should be placed on the first line of your HTML file.

Rate this script at Hotscripts.com

If you like my script, please rate it at HotScripts.com

Comments

No one has commented this - be first!

Post your comment

Don't have an avatar? Create one at Gravatar.com.

Confirmation code:

Go to cbolson.com


About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2024 dhtmlgoodies.com