JavaScript Answer Example 2
(For Advanced Users Only)

Description:
This reference page contains a basic example of how you can use standard HTML <FORM> components and JavaScripts to create your own custom method of answering MULTIPLE-CHOICE questions. In this example, an HTML <FORM> is created with 4 "radio" buttons. When any of the "radio" buttons are clicked, a JavaScript is called to set the selected answer via the uTestJSI.answerQuestion() API.

Example:

Below is what the example looks like:
A. England
B. France
C. Both A and B
D. None of the above.

And here is the HTML used to create the radio buttons and the JavaScript to handle when one of the buttons is clicked:
<SCRIPT LANGUAGE="Javascript">
function answerQ0014()
{
   // First get the selected answer from the FORM.
   var answer = "";
   if (document.Q0014.answer[0].checked == true)
   {
      answer = document.Q0014.answer[0].value;
   }
   else if (document.Q0014.answer[1].checked == true)
   {
      answer = document.Q0014.answer[1].value;
   }
   else if (document.Q0014.answer[2].checked == true)
   {
      answer = document.Q0014.answer[2].value;
   }
   else
   {
      answer = document.Q0014.answer[3].value;
   }

   // Now set the answer on the answer sheet.
   document.uTestJSI.answerQuestion("14",               <!-- Question Number -->
                                    "MULTIPLE_CHOICE",  <!-- Question Type -->
                                    "5",                <!-- Question Points -->
                                    "NONE",             <!-- Question Classification -->
                                    answer);            <!-- Selected Answer -->
}
</SCRIPT>

<FORM NAME="Q0014">
<INPUT TYPE=radio NAME="answer" VALUE="A" onClick="answerQ0014()"> A. England
<BR>
<INPUT TYPE=radio NAME="answer" VALUE="B" onClick="answerQ0014()"> B. France
<BR>
<INPUT TYPE=radio NAME="answer" VALUE="C" onClick="answerQ0014()"> C. Both A and B
<BR>
<INPUT TYPE=radio NAME="answer" VALUE="D" onClick="answerQ0014()"> D. None of the above.
</FORM>

Note: Don't forget to add the uTestJSI applet to your page too:
<APPLET CODE="uTestJSI.class" CODEBASE="../classes/" NAME="uTestJSI" WIDTH="2" HEIGHT="2">
</APPLET>

More Information:

For more information about creating and using your own HTML FORMs and JavaScripts with uTest, see uTest and JavaScripts.