0

I am creating an practice exam for some students in my school. I have a lot of multiple choice questions and i'm trying to get it to work bud got stuck here. I am new to javascript and have no clue on how to get this working. So every question has 4 choices that look like this:

<tr>
    <td>
        <figures1></figures1>
    </td>
    <td class="questiona">
        <br>
        <input type="radio" name="q1" value="a"/>a<br>
        <input type="radio" name="q1" value="b"/>b<br>
        <input type="radio" name="q1" value="c"/>c<br>
        <input type="radio" name="q1" value="d"/>d<br>
    </td>
</tr>

The question is just an image and they have to select either a, b, c or d. I've managed to get it working this far, bud what i want to add is an dialog whenever they click on a, b, c or d to tell them if the answer is correct or not and if not add a feedback to tell them why the answer is wrong. The reason why i am not using alert to give them a feedback is because i can't add images to an alert box.

Thanks in advance

Adrian Forsius
  • 1,437
  • 2
  • 19
  • 29
rickert
  • 5
  • 5

5 Answers5

1

Give your input a class like "answer". Then in your jquery code:

   $(document).ready(function(){
        $(".answer").click(function(){
            ValidateAnswerFunction(this); //sends the input element to the validate answer function
            $( "#dialog" ).css("display", "block"); // shows the dialog .hide(); to hide it!
        });

       $("#dialog").click(function(){
           $(this).hide();
       });
    });

   function ValidateAnswerFunction(input){
       switch($(input).val()){
           case "a":
               $("#dialog").html("correct");
               break;
           case "b":
               $("#dialog").html("close");
               break;
           case "c":
               $("#dialog").html("not even close <img src='http://www.w3schools.com/html/pic_mountain.jpg' style='width:100px;height:100px'>");
               break;
           case "d":
               $("#dialog").html("are you even trying m8?");
               break;
       }
   }

Where #dialog is your dialog:

<div id="dialog"></div>

JS fiddle

Stijn Bernards
  • 1,091
  • 11
  • 29
0

You'd need to test the value of the clicked element and then give feedback from that answer. This can be done i varity of ways, but I'd say that using $("[name=q1]").click() would be the easiest, and then use $(this).val() to check the answer.

Please refer to this fiddle for an example.

http://jsfiddle.net/u3csoave/

Fizk
  • 1,015
  • 1
  • 7
  • 19
0

you can use confirmation alert to achieve this.there are too many jquery demo's available.

for example see this link:how to show confirmation alert with three buttons 'Yes' 'No' and 'Cancel' as it shows in MS Word

Community
  • 1
  • 1
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
0

i think you can use confirmation alert to show user correct answer and put a link in the alert box which allows them to change their answer.

Kajal
  • 1
  • 1
0

JQueryUI dialog..

function foobar() {
   $("#dialog").dialog();
}

<div id="dialog" title="Dialog title">
   <img src="foo.bar"/>
</div>

Then open dialogs in radiobuttons' onlick method.

Maybe you should just make one generic dialog and pass all the information needed as parameters so you don't end up with a page containing multiple dialogs.

Olli Puljula
  • 2,471
  • 1
  • 14
  • 8