Help
Example

This example uses a course resource and the Javascript API to define a custom question. It changes the rendering of the existing true/false question from a radio button to a checkbox.

The following is the true-false question definition in the assessment. Notice that the question has the "Custom" property, and it refers to the TrueFalse.xml, which is the course resource that defines how to render the question:

Type: MC
Custom: TrueFalse.xml
Var: odd = 3..20,2
1) $odd$ is an odd number
*a. True
z. False

The following is the TrueFalse.xml that should be uploaded to the course as a resource. It uses the $QUESTIONID$ substitution variable to uniquely identify each question so that you can have multiple checkbox questions in the same assessment:

<custom>
<version>2</version>
<display>Active,Review,Print,PrintKey,Template</display>
<body mode="Active">
<![CDATA[
<i>Loading...</i>
<script type="text/javascript">
function saveMethod$QUESTIONID$()
{
    saveInfo = CQ.getInfo($QUESTIONID$)
    checkBox = document.getElementById("check$QUESTIONID$");
    index = 1;
    if (checkBox.checked) index = 0;
    CQ.setAnswer($QUESTIONID$,saveInfo.question.choices[index].id);
}
info = CQ.getInfo($QUESTIONID$)
myDiv = document.getElementById(info.divId);
myDiv.innerHTML = '<input type="checkbox" id="check$QUESTIONID$" /><label for="check$QUESTIONID$">&nbsp;' + info.question.body + '</label>';
CQ.onBeforeSave(saveMethod$QUESTIONID$);
</script>]]>
</body>
<body mode="Review">
<![CDATA[
<i>Loading...</i>
<script type="text/javascript">
info = CQ.getInfo($QUESTIONID$)
myDiv = document.getElementById(info.divId);
var checked = '';
if (info.submission.answer == info.question.choices[0].id) checked='checked="true" ';
myDiv.innerHTML = '<input type="checkbox" disabled="true" '+ checked + '/>&nbsp;' + info.question.body;
</script>
]]>
</body>
<body mode="Print,PrintKey">
<![CDATA[
<i>Loading...</i>
<script type="text/javascript">
info = CQ.getInfo($QUESTIONID$)
myDiv = document.getElementById(info.divId);
var checked = '';
if (info.mode == 'PrintKey' && info.question.answers[0] == info.question.choices[0].id) checked='checked="true" ';
myDiv.innerHTML = '<input type="checkbox" ' + checked + ' />&nbsp;' + info.question.body;
</script>
]]>
</body>
<body mode="Template">
<![CDATA[
  <question>
    <body></body>
    <interaction type="choice">
      <choice id="1">
        <body>True</body>
      </choice>
      <choice id="2" last="true">
        <body>False</body>
      </choice>
    </interaction>
    <answer>
      <value>1</value>
    </answer>
  </question>
]]>
</body>
</custom>
See Also
Advanced Assessment Editor <custom> Javascript API