Hi everyone, I am a begginer in JQuery and I want to make a simple matching quiz so I used this code to create the qustions div and answers div
edit:
<HTML>
<HEAD>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
</HEAD>
<BODY onload="location.href='#bottom'">
<form id="f1" action="#" method="post" >
<div id="Qdiv" style="position: absolute; top:242px; left:0px; wedth:120px">
<div id="q1" class="question"><label id="q1l"> The Capital of KSA</label></div>
<div id="q2" class="question"><label id="q2l"> The Capital of UK</label></div>
<div id="q3" class="question"><label id="q3l"> The Capital of USA</label></div>
</div>
<div id="answerDiv" style="position: absolute; top:242px; left:140px; wedth:100px">
<div id="a1" class="drag answer"><label id="a1l"> Riyadh</label></div>
<div id="a2" class="drag answer"><label id="a2l"> London</label></div>
<div id="a3" class="drag answer"><label id="a3l"> Washington</label></div>
</div>
<input type= "submit" id="sub1" value="Submit" style="position: absolute; top:310px; left:70px; /><br />
</form>
<img src="images/correct.png"id="myImage"style="display: none;"/>
<img src="images/false.png"id="myImage1"style="display: none;"/>
<a name="bottom"style="position: absolute; top:300px; left:70px;" ></a>
<script>
$(function() {
$("#a1").draggable();
$("#q1").droppable({
accept: '#a1', //I used this to make only a1 acceptable for q1
drop: function(event, ui) {
$(this).addClass('ui-state-highlight').find('label').html('Dropped!'); // this is just for testing if accept works
}
});
});
$(function() {
$("#a2").draggable();
$("#q2").droppable({
accept: '#a2', //I used this to make only a2 acceptable for q2
drop: function(event, ui) {
$(this).addClass('ui-state-highlight').find('label').html('Dropped!'); // this is just for testing if accept works
}
});
});
$(function() {
$("#a3").draggable();
$("#q3").droppable({
accept: '#a3', //I used this to make only a3 acceptable for q3
drop: function(event, ui) {
$(this).addClass('ui-state-highlight').find('label').html('Dropped!'); // this is just for testing if accept works
}
});
});
$(function() {
$('f1').submit(function() {
$('.question').each(function() {
var $question = $(this);
var $answer = $(this).find('.answer');
if ( $answers.length < 1 ) {
alert(' you must provide all answers');
return false;
}
var answerId = $answer.attr('id');
var $answerForm = $(this).append('<input type="hidden" value="' + answerId + '" name="answer_' + $(this).attr('id') + '" />');
});
});
});
</script>
</body>
</html>
I want to enable the user to drag Riyadh, London, and Washington to any of The capital of KSA The capital of UK The capital of USA and submit his/her answer after submitting it I want the button handler to check if every draggable is above its correct droppable. If yes, correct.png appears. othewise false.png appears.
I really thank u mr.Dan Heberden for your help but I tried ur code and it doesn't show what I expect like the alert(' you must provide all answers'); and I couldn't find out why.
I tried to use other codes but they also fail, sorry for being bothersome but I really need your help so I posted my whole page :$
your help will be appreciated :)