Combining Cloze-Type and MultipleChoice-Functionality with JavaScript

Combining Cloze-Type and MultipleChoice-Functionality with JavaScript

by Oliver Killgus -
Number of replies: 0

Is the there a way of combining the flexibilty of the cloze-type with the simplicity of a multiple-choice-type? 

I tried applying the following hack, using cloze in Moodle 2.7 - probably the same as in 2.8 (not tested) - adding JavaScript. I have been using YUI 3. You can easily rewrite it in jQuery. Click von input-fields to insert or remove "x".

<p>Question 1</p>
<h4>How many legs does a dog have?</h4>
<div class="test_short_input"> <--! introducing a reference -->
<p>{0:SHORTANSWER:=a} two </p>
<p>{1:SHORTANSWER:=x} four</p>
<p>{1:SHORTANSWER:=x} in case of an accident they there might be less than four left</p>
<p>{1:SHORTANSWER:=x} as many as a cat or a cow or a horse</p>
<p>{0:SHORTANSWER:=a} three</p>
</div>
<script type="text/javascript">// <![CDATA[
YUI(M).use('node', function(Y){ // after rendering, search for all input-Elements inside class test_short_input.
var mylist = Y.all('.test_short_input input');
mylist.each(function(item){
item.set('value', ' ');         // first run: fill all input-Elements with something in order to complete the form
item.removeAttribute('size');
item.setAttribute('size', '1');
item.on('click', function(){    // Eventhandler: onClick fill input-Elements with "x" or replace it by " "
    var test = item.get('value');
    if (test == 'x'){     item.set('value', ' ') } else{     item.set('value', 'x') }
    });
});
});
// ]]></script>

- Well, this is not a big thing. It can be usefull when adjusting the cloze question type to a given requirement in online-exams.  

Average of ratings: -