Use this very simple question example to create a User-Defined question to observe its behavior in the Developer. The code can be modified to meet your question needs. 


This sample code includes diagnostic feedback that appears at the top of the question. There are 4 parameters (kpnextpage, kpmode, kpfeedbk, kprnda) that are populated from the Knowledge Center and one parameter (kpremed) populated from the Developer.


kpnextpage: This parameter is the full URL to the portal page where tracking data is sent.

kpmode: This parameter indicates if a question is being played within a course, pre-assessment, or post-assessment.


kpfeedbk: This parameter indicates if feedback is enabled within the assessment. The parameter is on, by default, for courses.


kprnda: This parameter indicates if answers are randomized in order. This parameter is off, by default, for courses.


kpremed: This parameter indicates the remediation mode currently set within the course or assessment.

 

Note: To remove these parameters from your question, delete the bolded code from the example code. 


Sample User-Defined Question Code

 

<html>
<head>
<meta content="en-us">
<meta content="text/html; charset=windows-1252">
<title>Custom Question Page</title>
<script>
 


var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false; 


function GetQueryStringValue(param) { 


var strQueryString;
 
if (self.location.search.length>1) {
  // this was a get request where the results are in location.search (URL?...)
  strQueryString = self.location.search.substr(1);
}
else if (self.location.hash.length>1) {
  // this used the hash method (URL#...)
  strQueryString = self.location.hash;
}
 


var QueryItems = strQueryString.split("&");
for (var i=0; i < QueryItems.length; i++){
  var QueryItem = QueryItems[i];
  var intEqPos = QueryItem.indexOf("=")
  var strName = QueryItem.substr(0, intEqPos)
  if (strName == param) {
   return QueryItem.substr(intEqPos+1)
  }
}
 
// no querystring item found
return "";
}
 


var kpmode = GetQueryStringValue("kpmode");
var kpremed = GetQueryStringValue("kpremed");
var kpfeedbk = GetQueryStringValue("kpfeedbk");
var kprnda = GetQueryStringValue("kprnda");
var kpResultURL = GetQueryStringValue("kpnextpage");
 

 


function SendResult(score, answer){ 


// code to send score and answer back to Knowledge Pathways
 
// get the nextpage and target from querystring
 


   


if (kpResultURL == "") {
  // we must have an URL
  alert("no result URL supplied.");
  return false;
}
 
 


if (isNaN(score)) {
  // the score must be numeric
  alert("the score must be a numeric value.")
  return false;
}
 

 


 
// send get request back to the target frame
if ((kpResultURL.indexOf("?") >= 0) ||  (kpResultURL.indexOf("#") >= 0)){
  // the url already contains a ? or #, append to current querystring
  window.location.href = kpResultURL + "&score=" + score + "&answer=" + escape(answer);
}
else {
  window.location.href = kpResultURL + "?score=" + score + "&answer=" + escape(answer);
    }
 

 


return true;
}
 


function ProcessResult() { 


// determine if the answer is correct, if correct score = 1
// else the score is 0
 
var objForm = window.document.QuestionForm;
var score;
var message;
 
var answer = "";
 


for (var i=0; i<objForm.elements.length;i++) {
  if (objForm.elements[i].name == "answer") {
   if (objForm.elements[i].checked) {
    if (i == 0) {
     // correct answer setting score to 1
     score = 1;
     if (kpfeedbk == "1") {
      if (kpremed == "0") {
       // remediation not enabled
       message = "Correct!";
      }
      else {
       message = "Correct! 1+1 does equal 2.";
      }
      alert(message);
     }
    }
    else {
     // incorrect answer setting score to 0
     score = 0;
     if (kpfeedbk == "1") {
      if (kpremed == "0") {
       message = "Incorrect.";
      }
      else {
       message = "Incorrect. 1+1 equals 2.";
      }
      alert(message);
     }
    }
    // pull the answer from the radio options value
    answer = objForm.elements[i].value;
   }
  }
}
 
SendResult(score, answer)
}
 


</script>
</head>
 


<body>
<h3>User-Defined Question Example</h3>
<p>Available parameters:</p>
<Script>
document.write("kpmode indicates if the question is being played within a course, pre-assessment or post-assessment.</b>");
if (kpmode != "") {
  switch(kpmode){
   case "0":
    document.write("Question was launched from a <b>Course</b>");
    break;
   case "2":
    document.write("Question was launched from an <b>Assessment</b>");
    break;
  }
  document.write("<br><br>");
}
 


document.write("kpremed indicates the remediation mode currently set within the course or assessment.</b>");
if (kpremed != "") {
  switch(kpremed){
   case "0":
    document.write("Remediation mode(kpremed) is <b>(0) Off</b>");
    break;
   case "1":
    document.write("Remediation mode(kpremed) is <b>(1) User Asks</b>");
    break;
   case "2":
    document.write("Remediation mode(kpremed) is <b>(2) Incorrect</b>");
    break;
   case "3":
    document.write("Remediation mode(kpremed) is <b>(3) All</b>");
    break;
  }
  document.write("<br><br>");
}
 


document.write("kpfeedbk indicates if feedback is enabled within the assessment. Always enabled in courses.</b>");
if (kpfeedbk != "") {
 


  switch(kpfeedbk){
   case "0":
    document.write("Feedback(kpfeedbk) is <b>NOT enabled</b>");
    break;
   case "1":
    document.write("Feedback(kpfeedbk) is <b>enabled</b>");
    break;
  }
  document.write("<br><br>");
}
 


document.write("kprnda indicates if answers should be randomized in order. Always disabled in courses.</b>");
if (kprnda != "") {
  switch(kprnda){
   case "0":
    document.write("Random Answer(kprnda) is <b>NOT enabled</b>");
    break;
   case "1":
    document.write("Random Answer(kprnda) is <b>enabled</b>");
    break;
  }
  document.write("<br><br>");
}
 


document.write("kpnextpage indicates the full URL to the Portal page to which tracking data must be sent.</b>");
if (kpResultURL != "") {
  document.write("Tracking data URL: <b>" + kpResultURL + "</b>");
  document.write("<br><br>");
}
 
</script>
 


<form method="GET" action=""  name="QuestionForm" target="">
  <p>Example question:</p>
  <p>1+1=</p>
  <p><input type="radio" value="2" checked name="answer">2</p>
  <p><input type="radio" name="answer" value="42">42</p>
  <p><input type="button" value="Submit" name="Submit" onClick="ProcessResult(); return false">
  <input type="reset" value="Reset" name="B2"></p>
 


</form>
</body>
</html>
 


To create a User-Defined question using the example HTML:

  1. Copy the User-Defined example HTML and paste into Notepad or other program and save with an .htm extension.
     
  2. On the File menu, point to New New, and choose Package Package.
     
  3. Add the .htm file to the package.
     
  4. Save the new package document.
     
  5. On the File menu, point to New New, point to Question Question, and choose User-Defined.
     
  6. Click Update Link Update Link and navigate to the package containing the user-defined question.
     
  7. Select the .htm file.
     
  8. Click Open.
     
  9. Select the percentage of correct answers (0-100%) needed to pass the question in the Correct Score field.
     
  10. Save the question.

To create a User-Defined question:

  1. On the File menu, point to New New, point to Question Question, and choose User-Defined.
     
  2. Click Update Link Update Link and navigate to the package containing the user-defined question.
     
  3. Select the file containing the code.
     
  4. Click Open.
     
  5. Select the default value in the Correct Score field.
     
  6. Save the question.

Table of Contents