Don't like ads? PRO users don't see any ads ;-)
Guest

Formative Test Form

By: a guest on Mar 19th, 2012  |  syntax: HTML  |  size: 0.92 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <SCRIPT language="JavaScript" type="text/javascript">
  2.  function checkFormativeTest(testForm, rightAnswer)
  3.  {
  4.    var choice;
  5.  
  6.    for(i = 0;i<testForm.elements.length;i++)
  7.   {
  8.     if(testForm.elements[i].checked)
  9.     {
  10.       choice = testForm.elements[i].value;
  11.     }
  12.   }
  13.  
  14.   switch(choice)
  15.   {
  16.    case undefined:
  17.     alert("Please make a selection.");
  18.         break;
  19.         case rightAnswer:
  20.     alert("'"+choice+"' is correct!");
  21.         break;
  22.         default:
  23.     alert("'"+choice+"' is incorrect.");
  24.   }
  25.  
  26.   return false;
  27. }
  28. </SCRIPT>
  29.  
  30. ------------------------------------------------------------------------
  31.  
  32. Question?
  33. <form method="POST" onSubmit="return checkFormativeTest(this,'B');">
  34.   <input type="radio" value="A" name="">
  35.   A. Answer A
  36.  
  37.   <input type="radio" value="B" name="">
  38.   B. Answer B
  39.  
  40.   <input type="radio" value="C" name="">
  41.   C. Answer C
  42.  
  43.   <input type="submit" value="Submit Answer">
  44. </form>