Alert box shows up multiple times on javascript
<p>This is very simple code, and similar to my other question.
When I click submit, the alert box shows up three times for option one, twice for two, and once for three.</p>

<p>Here is the part of the code where the problem is most probably located:</p>

<pre><code>var chosen = ""
var len = document.ExamEntry.r1.length

for (var i = 0; i &lt; len; i++) {
  if (document.ExamEntry.r1[i].checked) {
    chosen = document.ExamEntry.r1[i].value
  }
  if (chosen != "") {
    confirm(chosen)
  }
}
</code></pre>

<p>And here is my whole code. It all works fine except for this.</p>

<pre><code>&lt;!-- saved from url=(0055)file:///C:/Users/Bartek/Downloads/Exam%20entry4.1.2.htm --&gt;
&lt;html&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Exam Entry Form&lt;/h1&gt;
    &lt;form name="ExamEntry" method="post" action="file:///C:/Users/Bartek/Downloads/success.html"&gt;
        &lt;input type="radio" name="r1" value="GCSE"&gt;GCSE
&lt;input type="radio" name="r1" value="AS"&gt;AS
&lt;input type="radio" name="r1" value="A2"&gt;A2
&lt;table width="50%" border="0"&gt;
            &lt;tbody&gt;
&lt;tr&gt;
                &lt;td id="name" style="color: black; "&gt;Name&lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="text" name="name"&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td id="subject" style="color: black; "&gt;Subject&lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="text" name="subject"&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
&lt;tr&gt;
                &lt;td id="enumber" style="color: black; "&gt;Examination Number&lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="text" name="enumber"&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;input type="submit" name="Submit" value="Submit" onclick=" return validateForm();"&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="reset" name="Reset" value="Reset"&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/tbody&gt;&lt;/table&gt;
    &lt;/form&gt;

&lt;script&gt;
function validateForm() {
  var result = true;
  var msg = "";
  if (document.ExamEntry.name.value == "") {
    msg += "You must enter your name \n";
    document.ExamEntry.name.focus();
    document.getElementById('name').style.color = "red";
    result = false;
  }
  if (document.ExamEntry.subject.value == "") {
    msg += "You must enter the subject \n";
    document.ExamEntry.subject.focus();
    document.getElementById('subject').style.color = "red";
    result = false;
  }
  if (document.ExamEntry.enumber.value.length != 4) {
    msg += "The examination number must be exactly four characters long \n";
    document.ExamEntry.enumber.focus();
    document.getElementById('enumber').style.color = "red";
    result = false;
  }
  var chosen = ""
  var len = document.ExamEntry.r1.length

  for (var i = 0; i &lt; len; i++) {
    if (document.ExamEntry.r1[i].checked) {
      chosen = document.ExamEntry.r1[i].value
    }
    if (chosen != "") {
      confirm(chosen)
    }
  }
  if (msg == "") {
    return result;
  } {
    alert(msg);
    return result;
  }
} 
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;  
</code></pre>

<p>This is GCSE computing coursework.</p>
