## Quiz

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.

In my cloze question type, ({1:MULTICHOICE:No Idea  ~=True  ~False}

That is, change

to look like this

о No Idea            о True                   о False

(Displayed horizontally)

Thanks

Tieku

Average of ratings: -

Tieku,

As far as I know there is no embedded radio button type question in CLOSE (I’m still on 1.6.3 but I don’t think this has changed). What you can do is add to the question your own radio buttons and set the onBlur event of those radio buttons to copy their value to the Moodle MULTICHOICE field which you can have either visible or hidden. See this post for how it can be done. The example works with SHORTANSWER and if you keep these fields hidden that it might be simpler to construct but you can do that also with the MULTICHOICE in which case you need to manipulate the selectedindex. Also in that example accessing the Moodle field requires to extract its id, but it can be done dynamically by navigating the DOM and you can find an example of that in this post.

Itamar

Average of ratings: -

Itamar,

I read the post but don't understand what to do. So what would be  the equivalanet for

 {1:MULTICHOICE:No Idea ~=True ~%-100%False}

This is how I want the questions diplayed:

 Question Here oNo Idea      oTrue     oFalse

Tieku

Average of ratings: -
Here is one way to do it:

<tbody>
<tr>
<td valign="top">The answer to this question is true</td>
<td valign="top"><input name="yaynay" onclick="this.parentNode.parentNode.childNodes[3].firstChild.selectedIndex=1;" type="radio" />True</td>
<td valign="top"><input name="yaynay" onclick="this.parentNode.parentNode.childNodes[3].firstChild.selectedIndex=2;" type="radio" />False</td>
<td valign="top">{:MULTICHOICE:=True#~False#}</td>
</tr>
</tbody>
</table>

On clicking one of the radio buttons the Moodle MULTICHOICE is set. If you change anything in the table structure you may need to change the DOM path from the radio button to the MULTICHOICE field (that's the onclick command string).

You can see that the radio button values are not preserved after submission but with a little bit more work they can be restored and then you can hide the MULTICHOICE filed by setting the TD display style to none.

I hope that helps. Let me know if you need more details.

Itamar

Average of ratings: -
Here is a simple code for restoring the radio button values after submission:

<script type="text/javascript">
<!--
var sel=document.getElementsByTagName("select");
for (i=0;i<sel.length;i++){
var ind=sel[i].selectedIndex;
sel[i].parentNode.parentNode.childNodes[ind].firstChild.checked=true;
}
}
-->
</script>

It should be included once in every quiz page. The DOM path assumes the above table structure so if you change that structure you may need to change the path. Let me know if it works for you.

Itamar

Average of ratings: -
I couldn't resist it:

Average of ratings: -
By the way, I don't think you need the 'No Idea' as it is the default when none of the radio buttons is checked. Moreover, any reasonable student will prefer choosing either True of False over No Idea even if he or she has no idea simply because 'No Idea' is not really a possible answer to the question.

Average of ratings: -

I will take a look at the code and see whether I can get it to work. How come I see the radio buttons and also the drop down?

The reason why I need “No Idea” is students are penalized for wrong responses. So a student should have an option not answer if he is not sure, or change answer from True or False. So here is how the points are awarded.

No Idea – 0

True +1 or -1

False +1 or -1

Average of ratings: -
The drop down has to be there because this is how the quiz marks the question. And you can see it because if it were hidden you wouldn't understand what I'm referring to. But you can easily hide it as I suggested above.

Average of ratings: -

Hello Itamar,

Thanks for the help. I am not a programmer and I am not familiar with PHP coding, but if you let me know where exactly everything should be put, I should be able to do it.

Did you understand my explanation for needing radio a button for “No Idea”? I have a separate hack that subtracts a point for incorrect responses (to discourage guessing) so a student who does not want to risk losing a point when they are not sure should have the option of no answering, which is the “No idea” radio button. That is why in Multichoice I have {1:MULTICHOICE:No Idea ~=True ~%-100%False}and

{1:MULTICHOICE:No Idea ~%-100%True ~=False}

Please put all the steps in one reply for me (and where exactly they go):

1. Replace drop down with radio buttons

2. Copy radio buttons values to the Moodle MULTICHOICE field

3. Hide multichoice drop down

4. Preserving radio button values after submission

For example where exactly do I it put the code below:

<script type="text/javascript">
<!--
var sel=document.getElementsByTagName("select");
for (i=0;i<sel.length;i++){
var ind=sel[i].selectedIndex;
sel[i].parentNode.parentNode.childNodes[ind].firstChild.checked=true;
}
}
-->
</script>

Tieku

Average of ratings: -
Hi Tieku

• Create a Cloze question
• In the question's text editor change to html mode ()
• Paste the following html code
<tbody>
<tr>
<td style="padding-right: 20px;" valign="top">Enter question description here</td>
<td style="background-color: rgb(221, 221, 221);" valign="top"><input name="YYYY" Xonclick="this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=1;" type="radio" />Not Sure</td>
<td style="background-color: rgb(221, 221, 221);" valign="top"><input name="YYYY" Xonclick="this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=2;" type="radio" />True</td>
<td style="background-color: rgb(221, 221, 221);" valign="top"><input name="YYYY" Xonclick="this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=3;" type="radio" />False</td>
<td style="visibility: hidden;" valign="top">{:MULTICHOICE:Not Sure#~=True#~False#}</td>
</tr>
</tbody>
</table>

• Remove X
• replace YYYY with a unique name (must be different for each question if you have more than one question in a page)
• Set the desired correct answers in the MC fields
• Enter question description where it says 'Enter question description here'
• Save
• Create a Description question
• In the question's text editor change to html mode ()
• Paste the following code
<script type="text/javascript">
<!--
var sel=document.getElementsByTagName("select");
for (i=0;i<sel.length;i++){
var ind=sel[i].selectedIndex;
sel[i].parentNode.parentNode.childNodes[ind].firstChild.checked=true;
}
}
-->
</script>
• save
The description question is invisible from students perspective because it displays nothing. It must be included in each quiz page. If you have more than one page you will need to duplicate the question and give each instance a unique name (this at least is what I have to do in 1.6.3; I don't know if that has changed in subsequent versions).

That's about it. Give it a try and let me know how it works.

Itamar

P.S. If I may make a suggestion, 'No Idea' seems to me too strong as I might have an idea but I may not be sure enough to select the answer I think is the correct one. Perhaps 'Not Sure' will do more justice in such cases.

Average of ratings: -

Itamar,

Thanks for the step by step instructions. I will let you know how it goes. I like your suggestion for using Not Sure instead of No Idea.

Average of ratings: -

Itamar,

I coud not get it to work. Please see attached Word file for screenshots. Here is my code for the cloze question:

<tr>
<td style="padding-right: 20px" valign="top">This is Queston 1
</td>
<td style="background-color: rgb(221,221,221)" valign="top"><input onclick="function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=1; } } } } } }" type="radio" name="QUE1" />Not Sure
</td>
<td style="background-color: rgb(221,221,221)" valign="top"><input onclick="function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=2; } } } } } }" type="radio" name="QUE1" />True
</td>
<td style="background-color: rgb(221,221,221)" valign="top"><input onclick="function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=3; } } } } } }" type="radio" name="QUE1" />False
</td>
<td style="visibility: hidden" valign="top">{:MULTICHOICE:Not Sure#~=True#~%-100%False#}
</td>
</tr></tbody>
</table>

Average of ratings: -
Is function anonymous the hack for wrong answer penalty? Could you first try the code without that function and see if it works? Then tell me what you are trying to do by this function. What seems to be the problem is that by placing the 'this.parent...' inside the function you change the 'this' reference. You can also try adding the function right after the 'this.parent...;' as a second command.

Average of ratings: -

No, I do not use function anonymous for my negative marks hack so I do not know whether it would be interfering with yours.

Here are the 2 files and functions I use:

File: moodle\lib\questionlib.php
function question_apply_penalty_and_timelimit(&$question, &$state, $attempt,$cmoptions)
{
// deal with penalty
if ($cmoptions->penaltyscheme) {$state->grade = $state->raw_grade -$state->sumpenalty;
$state->sumpenalty += (float)$state->penalty;
} else {
$state->grade =$state->raw_grade;
}

// deal with timelimit
if ($cmoptions->timelimit) { // We allow for 5% uncertainty in the following test if (($state->timestamp - $attempt->timestart) > ($cmoptions->timelimit * 63)) {
$state->grade = 0; } } // deal with closing time if ($cmoptions->timeclose and $state->timestamp > ($cmoptions->timeclose + 60) // allowing 1 minute lateness
and !$attempt->preview) { // ignore closing time for previews$state->grade = 0;
}

/* negative marks hack start: commented the line below
// Ensure that the grade does not go down
$state->grade = max($state->grade, $state->last_graded->grade); negative marks hack stop */ } File: moodle\question\type\multichoice\questiontype.php function grade_responses(&$question, &$state,$cmoptions) {
$answers =$question->options->answers;
$testedstate = clone($state);
$teststate = clone($state);
$state->raw_grade = 0; foreach($answers as $answer) {$teststate->responses = array('' => $answer->id); if($question->options->single) {
if($this->compare_responses($question, $testedstate,$teststate)) {
$state->raw_grade =$answer->fraction;
break;
}
} else {
foreach($state->responses as$response) {
$testedstate->responses = array('' =>$response);
if($this->compare_responses($question, $testedstate,$teststate)) {
$state->raw_grade +=$answer->fraction;
break;
}
}
}
}
if (empty($state->raw_grade)) {$state->raw_grade = 0;
}

/*  negative marks hack start
// Make sure we don't assign negative or too high marks
$state->raw_grade = min(max((float)$state->raw_grade,
0.0), 1.0) * $question->maxgrade; */$state->raw_grade = min((float) $state->raw_grade, 1.0) *$question->maxgrade;
// Negative marks hack stop

// Apply the penalty for this attempt
$state->penalty =$question->penalty * $question->maxgrade; // mark the state as graded$state->event = (state->event == QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; return true; } Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question That's the code you presumably used but the highlighted part (which appears in other lines too) shouldn't be there. (And I trust that you remove the X in the Xonclick too). Without it it should work. <table cellspacing="0" cellpadding="0" border="0"><tbody> <tr> <td style="padding-right: 20px" valign="top">This is Queston 1 </td> <td style="background-color: rgb(221,221,221)" valign="top"><input Xonclick=" ****function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { **** this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=1; **** } } } } } }**** " type="radio" name="QUE1" />Not Sure </td> <td style="background-color: rgb(221,221,221)" valign="top"><input Xonclick="function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=2; } } } } } }" type="radio" name="QUE1" />True </td> <td style="background-color: rgb(221,221,221)" valign="top"><input Xonclick="function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { function anonymous() { this.parentNode.parentNode.childNodes[4].firstChild.selectedIndex=3; } } } } } }" type="radio" name="QUE1" />False </td> <td style="visibility: hidden" valign="top">{:MULTICHOICE:Not Sure#~=True#~%-100%False#} </td> </tr></tbody> </table> Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I tried it again from scratch. I realize that when i paste the code for the cloze question in html mode, make all changes (delete X and replace YYYY etc), close it the question editor, and open it again, the function anonymous appears on its own. Where is this coming from? Looks like someone had the same problem: http://moodle.org/mod/forum/discuss.php?d=8927 and why is the X put infront of onclick, only to be removed? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question This is another question. In the drop down menu for multiple choice in cloze type questions, is there a way of letting the word “Choose…” show the way it does for Matching questions: Multiple choice cloze: /stroke>/f>/f>/f>/f>/f>/f>/f>/f>/f>/f>/f>/f>/formulas>/path>/lock>/shapetype>/imagedata>/shape> Matching /imagedata>/shape> Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Itamar, I picked up the following from a help page for Format for a question: Help on writing html When writing HTML in Moodle, you are free to use almost any HTML tags you like to produce the effect you want. Note that scripting (eg Javascript or VB Script) is not allowed, and will be removed automatically. Your code will normally be printed on the page within a table cell, so: * there is no need to use any <HEAD> or <BODY> tags * be careful about unmatched </TABLE> tags that may mess up the display. Smilies (emoticons) will be converted into their graphical equivalent, and bare URLs will be converted into links. Is this perhaps why i cant get your javascirpt for the radio buttons to work? i am still trying to get it to work. Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Dears, Itamar's solution (first part of it) worked fine with me. But, the 2nd part which should preserve the radio-buttons state didn't work so the radio state is lost after submitting the answer. When I place the given javascript in a Description Question and let it run as directed in the solution it gives error. It looks that Description Questions don't accept javascrip ?? or some other unknown problem ! Itamar Tzadok replied to an email for me saying there was more work around for this issue was done outside this discussion and he asked me for the link of this discussion session (which I sent it) but no reply for this problem. Any help ! Thanks, Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Just to say that in 1.9 you have now the possibility to format the multichoice with radio buttons either horizontally or vertically. Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, where is the option in multichoice to format with radio buttons horizontally? Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I just realize that the help file has not been put on 1.9 although the code is already there. See The help file of new Cloze multianswer, your suggestions... and A more versatile Cloze multianswer question type? Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, I have read through this, but has this been actually implemented? I do not see the different display options (vertical, horizontal) when I go to create a multichoice question? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Which version of Moodle are you using? Pierre P.S. This is available on 1.9.3 although the help file is not changed. You could see an additional item (layout) when using decode and analyze the question. Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Thanks Piere, thanks Tieku, I used the Demo site and the Multi-Choice Horizontal works fine as you can see below: I used it for images questions as you see.The only problem is the background color. My images are all white and the options (table) background is colored. I want to change the table cells color to be white. The other thing is to remove these small cells that are reserved for the feedback. Appreciating any help, Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I use the standard way to display multichoice. Pierre P.S. "I used the Demo site" which one? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question This is the demo site that I used: http://demo.moodle.org/ Then I selected Moodle Features Demo link: http://demo.moodle.org/course/view.php?id=2 It shows the MCH as I said earlier. But playing with colors might be a theme issue. Is that true? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Demo site - demo.moodle.org Can i get a screen shot of the page where you specify the option for horizontal display of answer choices, or how to get there? Still can't find it. Is this possible for cloze or multichoice type questions? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question See MDL-14763 Here is the new file Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Thanks Pierre, looks like this is what i have been looking for. Will give it a try and see. Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, so that worked. I have three questions: 1. When will you update the help file for Adding Embedded Answers (Cloze)? 2. Can I get rid of the automatic numbering of answer choices in MCH (1, 2, 3…) 1. What is the significance of 2 in {2:MCH: Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question 1. This has been CVS yesterday on 1.9 merged and HEAD 2. No. I don't want to get to more options than necessary because the Cloze syntax is already quite complex... 3. 2 is the question grade. Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, you wrote: 2. No. I don't want to get to more options than necessary because the Cloze syntax is already quite complex... I am not asking for more options. For the sake of someone who does not need the numbering, could you leave this blank, so that those who need numbers type it in, and those wanting to use a another scheme have the flexibility to do so? Thanks for your help. Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Effectively this is a good suggestion. I just eliminate the numbering and the user add what he want. Pierre P.S. MDL-14763 Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question So this means you will change it to NO numbering. Thank you very much! Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Done Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Done? I just went to demo.moodle.org to try it out and the numbers are still showing? Or do i download the latest version of moodle Moodle 1.9.3+ Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question The CVs are done on HEAD version and 1.9_MERGED. Each week 1.9MERGED is transfered to the MOODLE_19_WEEKLY You can go to http://cvs.moodle.org/moodle/ select 1.9Merged and you will access the most recent files. The current demo is Moodle 1.9.3+ build 20081029 i.e october 29 2008 Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, See attachment for what a typical cloze question using MCH will look like for me. 1. Can you replace the rectangle box, or double border (circled purple) that separates the different cloze answers choices (in my case, Not Sure, True, False with a single vertical line?) 2. Can you eliminate the extra white space after the last option (circled orange) I am using a table with 3 columns and 5 rows. Thanks. Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Could you add a .doc version as I am not Vista updated. Thanks Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, I am resending the document: See attachment for what a typical cloze question using MCH will look like for me. 1. Can you replace the rectangle box, or double border (circled purple) that separates the different cloze answers choices (in my case, Not Sure, True, False with a single vertical line?) 2. Can you eliminate the extra white space after the last option (circled orange) I am using a table with 3 columns and 5 rows. Thanks. Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I agree with tieku - what can be done to remove the "double border" or replace with a vertical line. Thanks! Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I will try to see what can be done using css or other HTML that the user can put in the question text. see http://moodle.org/mod/forum/discuss.php?d=116240 If you have any suggestions. Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I am the one Itamar helped to get this done. Here is the link: http://moodle.org/mod/forum/discuss.php?d=96915 There is a lot of information there. So if you tell me specifically what your are trying to achieve, i might be able to help you since it has worked for me. Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question I answer here to the last Tieku post. Ok to set a clear separation between the answers i.e. putting them in a distinct cell. Will try to set things so that all the space is used. Have to test with different settings. Pierre Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, I downloaded 1.9.3+ (Build: 20081119) yesterday with the updated MCH. Looks very good without the auto-numbering. Looking forward to the other changes just mentioned. Thanks. Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Tieky, You will have to live with the current display as this is the standard handling of multichoice for display the radio button, the different color when grading and giving the reports with the feedback. I cannot change this and the convention to click to radio at the left of the answer is standard. However there is no space left at right when testing on the last version. Pierre P.S. This has been CVS down to 1.8 Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Pierre, Thank you for your work on the MCH; it works very well. The current display is good and the changes I suggested are minor. I will download tomorrow to see the changes you made to take away the extra space to the right. Thanks. This has been CVS down to 1.8? What does this mean? Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Hello Pierre, I noticed with a recent download of Moodle that the output for the MCH cloze question type is not transparent as it used to be. Can you revert back to using a transparent background so that I can apply background colors to the table cell I put the MCH in? Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question Hello Pierre, I noticed with a recent download of Moodle that the output for the MCH cloze question type is not transparent as it used to be. Can you revert back to using a transparent background so that I can apply background colors to the table cell I put the MCH in? Tieku Average of ratings: - Re: Replace drop down menu with radio buttons in cloze question The table is defined as <table class="answer"> <tr class="<?php echo 'r'.row = $row ? 0 : 1; ?>"> <?php$row = 1; foreach ($anss as$answer) { ?>
<td class="c0 control">
<?php echo $answer->control; ?> </td> <td class="c1 text <?php echo$answer->class ?>">
<label for="<?php echo $answer->id ?>"> <?php echo$answer->text; ?>
<?php echo $answer->feedbackimg; ?> </label> </td> <td class="c0 feedback"> <?php echo$answer->feedback; ?>
</td>
<?php } ?>
</tr>
</table>
So the css classes( i.e. "answer") control the display.
I did not change the multianswer code but the css could have been changed or another theme chosen by your moodle site manager.
Pierre

Average of ratings: -
"there is no embedded radio button type question in CLOSE (I’m still on 1.6.3 but I don’t think this has changed)."

Effectively this has not changed because many people use cloze questions in text so they want the cloze display stay in-line so that it can be used to test puncuation mark for example.
The recent modifications has been to eliminate the space between the text and the input HTML field and to size the input HTML field in relation to answer size like the select element.

The Cloze question code convention cannot be changed and there was no provision for formatting the question.
The usefulness of Cloze question being its simple coding that allow you to create rapidly a complete quiz in a single question if you need it (i.e. at 10 p.m. for a 9.00 am course tomorrow morning

Pierre

P.S.Although your hacks are very clever, they remain hacks.
I think that we could modify the actual Decode and Verify the Question Text in the 1.8 + editing interface to add this layout option that could stored in the question_multichoice table.
However it could be not stored in the actual import-export cloze text format but could be in the backup and restore process.
It wouldl allow the Cloze display to meet some of the accessibility standards.

Average of ratings: -