title: Javascript: display an alert when a form is checked?
body: <p>I have created a simple web app that has 2 form selections, when the user makes their selection from each I want an <code>alert</code> to display showing them the choices they made.</p>
  
  <p>I have attempted this below but when both forms are checked the alert is <strong>not</strong> displayed. What am I missing? Note see the comment:</p>
  
  <pre><code> //BELOW IS NOT BEING DISPLAYED BUT SHOULD BE
  </code></pre>
  
  <p><strong>Current code:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Calculator&lt;/h1&gt;
  
  &lt;p&gt;Select the importance of this:&lt;/p&gt;
  
  &lt;form method="get"&gt;
    &lt;input type="checkbox" name="Severity" value="negligible"&gt; Negligible&lt;br&gt;
    &lt;input type="checkbox" name="Severity" value="minor"&gt; Minor&lt;br&gt;
  &lt;/form&gt;
  
  &lt;p&gt;Select the Probability of this:&lt;/p&gt;
  
  &lt;form method="get"&gt;
    &lt;input type="checkbox" name="Probability" value="improbable"&gt; Improbable&lt;br&gt;
    &lt;input type="checkbox" name="Probability" value="remote"&gt; Remote&lt;br&gt;
    &lt;input type="checkbox" name="Probability" value="occasional"&gt; Occasional&lt;br&gt;
  
  &lt;button onclick= "analyseThis()"&gt; Analyse this &lt;/button&gt; &lt;br&gt;
  
  
  
  &lt;script&gt;
  
  function analyseThis(){
  
      var severities = document.getElementsByName('Severity');
     var probs = document.getElementsByName('Probability');
  
    var severity = undefined;
    for(var i = 0; i &lt; ages.length; i++)
    {
      if(severities[i].checked)
      {
        age = severities[i].value;
  
      }
    }
  
     var probability = undefined;
     for(var i = 0; i &lt; probs.length; i++)
     {
        if(probs[i].checked)
        {
          probability = probs[i].value;
  
        }
      }
  
     //BELOW IS NOT BEING DISPLAYED BUT SHOULD BE
     alert("Severity is: " + age + "Probability is: " + probability);
  
  }
  
  &lt;/script&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>