New on DHTMLGoodies.com:

DHTML Chess Wordpress Plugin (Beta) . Participate in the beta testing of the DHTML Chess for WordPress plugin, and receive a free Commercial License worth USD99.

Download drag and drop quiz script

Demo (drag capitals) | Demo (simple math quiz)

Bookmark and Share

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.

Comments

austin
i had a question about a user interface modification - instead of the list of answers moving up when an answer is dragged off the list, i wanted to have a set of grey boxes underneath the answers on the right column, so that when a user dragged and dropped an answer he/she would see an empty container from where the answer was dragged and could return drag the answer to the spot? is that possible? how would that be accomplished?
austin at 12:33AM, 2012/02/20.
marc
I want to write an alert if the quiz is incorrecte.g. if correct alert ('well done'); else alert ('try again') Any help??/
marc at 08:57AM, 2012/05/17.
John
What's the code and form set-up to save this to SQL database with php or Ajax? Thanks for the pointers!
John at 02:17PM, 2012/09/01.
Aditya
Excellent! you are genius and amazing! visiting this site and seeing your work really made me so happy!One reason of my happiness is i did thought of similar idea but never implemented !
Aditya at 05:18AM, 2013/03/17.
Marco Silva
What's the code and form set-up to save this to SQL database with php?
Marco Silva at 10:04AM, 2013/07/29.
Ash
I’m currently using a script/form that has served a purpose for me for some time but I keep thinking back to a vision I had some time ago that I was never able to master. The closest thing I can find to what I want is shown here (above)http://www.dhtmlgoodies.com/scripts/drag-drop-quiz/drag-drop-quiz-d2.htmlbut it’s still not exactly what I’m after (im not looking for a quiz) Basically I am creating a team selection page for my users (there only a handful of them) What I would be doing is list on the right hand side of the screen, every available player in their squad (usually 45 names) and the on the left hand side of the screen, have empty boxes (18 of them) representing the positions on the field.There would also be a sub section below the 18 feild positions on the right for emergency players (6 of them) in case somebody got injured ect. My hope then would be that a user could: * Click a name on the left and drag it to a field position on the right, thus filling that position and removing the players name from the squad list (because he has been selected) * This would continue to happen until all field positions were full. * Once all positions were full, the user would click a submit button to send the chosen players to me in a plain text list via email * A user would be banned from clicking submit until all positions were filled. * A user could remove a player by dragging his name back out of a position (this would also re disable the submit button if the position is then not filled. * I've attached a photoshop view of my idea (sorry for it being out of allignment) and note that the sample might not follow the rules shown above (eg submit button visible before team it full Can't see the picture I can email it to you. In a nutshell the bare bones of my requirements are that I have a list of 45 names. What I need the form to do is allow a user to select 18 primary names from the list, and 6 secondary names from the list and have the form email me their selections in the order that they were chosen...... It must also ensure that no name was used twice.Is this still something that is too ambitious???
Ash at 10:52PM, 2013/12/14.
joseph
can you help with drag and drop form builder I'm trying to create? that goes for anyone else here as well
joseph at 12:17PM, 2014/02/09.
Sammy
Does this work for touchscreen devices/
Sammy at 11:24PM, 2015/04/08.
sagar
its not works in ipad please give the solution
sagar at 06:28AM, 2015/08/08.

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 - 2017 dhtmlgoodies.com