Radio Button Test With Result Computed

[Total: 0    Average: 0/5]

This shows how to create a test using a form.

Body Code:

<script type=text/javascript>
function showResults() {
  var numRight = 0;
  if (document.exf1.q1[document.exf1.q1r.value].checked) numRight++;
  if (document.exf1.q2[document.exf1.q2r.value].checked) numRight++;
  if (document.exf1.q3[document.exf1.q3r.value].checked) numRight++;
  document.exf1.score.value = numRight;
}
function init() { document.exf1.score.value = "?"; }
</script>
<form name=exf1>
<BR>
Q1: A <input type=radio name=q1 value="A" onfocus="init()">
    B <input type=radio name=q1 value="B" onfocus="init()">
    C <input type=radio name=q1 value="C" onfocus="init()">
    D <input type=radio name=q1 value="D" onfocus="init()">
    E <input type=radio name=q1 value="E" onfocus="init()">
	  <input type=hidden name=q1r value="0">
<BR>
Q2: A <input type=radio name=q2 value="A" onfocus="init()">
    B <input type=radio name=q2 value="B" onfocus="init()">
    C <input type=radio name=q2 value="C" onfocus="init()">
    D <input type=radio name=q2 value="D" onfocus="init()">
    E <input type=radio name=q2 value="E" onfocus="init()">
	  <input type=hidden name=q2r value="1">
<BR>
Q3: A <input type=radio name=q3 value="A" onfocus="init()">
    B <input type=radio name=q3 value="B" onfocus="init()">
    C <input type=radio name=q3 value="C" onfocus="init()">
    D <input type=radio name=q3 value="D" onfocus="init()">
    E <input type=radio name=q3 value="E" onfocus="init()">
	  <input type=hidden name=q3r value="2">
<BR>
<input type=button value="Show Score" onclick="showResults()">
<BR>
Score: <input type=text name=score value="?">
</form>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *