 <p>I have removed all unused code and left only addNumbers function. I have also removed events on each button - no such function.</p> <p>I sum over all checked radio buttons so if you have other on the page you probably need more specific selector.</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function addNumbers() { var selectedRadios = document.querySelectorAll('input[type="radio"]:checked'); var sum = 0; for (var i = 0; i &lt; selectedRadios.length; i++) { sum += parseInt(selectedRadios[i].value); } document.getElementById('answer').value = sum; var showDiv = sum &lt; 15 ? "lowResult" : (sum &lt; 25 ? "mediumResult" : "highRisk"); document.getElementById(showDiv).style.display = 'block'; }</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.results { display: none; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt; &lt;tr&gt; &lt;th scope="col"&gt;&lt;/th&gt; &lt;th scope="col"&gt;noRisk&lt;/th&gt; &lt;th scope="col"&gt;lowRisk&lt;/th&gt; &lt;th scope="col"&gt;mediumRisk&lt;/th&gt; &lt;th scope="col"&gt;HighRisk&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt; &lt;div class="lefttext"&gt;How old are you?&lt;/div&gt; &lt;/th&gt; &lt;td&gt; &lt;input type="radio" id="value1" name="selectedAge" value="0" checked&gt;1-25&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value1" name="selectedAge" value="5"&gt;26-40&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value1" name="selectedAge" value="8"&gt;41-60&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value1" name="selectedAge" value="10"&gt;1-25&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt; &lt;div class="lefttext"&gt;What is you BMI?&lt;/div&gt; &lt;/th&gt; &lt;td&gt; &lt;input type="radio" id="value2" name="selectedBmi" value="0" checked&gt;0-25&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value2" name="selectedBmi" value="0"&gt;26-30&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value2" name="selectedBmi" value="9"&gt;31-35&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value2" name="selectedBmi" value="10"&gt;35+&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt; &lt;div class="lefttext"&gt;Does anybody in your family have diabetes?&lt;/div&gt; &lt;/th&gt; &lt;td&gt; &lt;input type="radio" id="value3" name="selectedDiabete" value="0" checked&gt;No&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value3" name="selectedDiabete" value="7"&gt;Grandparent&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value3" name="selectedDiabete" value="15"&gt;Sibling&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value3" name="selectedDiabete" value="15"&gt;Parent&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th scope="row"&gt; &lt;div class="lefttext"&gt;How would you describe your diabete&lt;/div&gt; &lt;/th&gt; &lt;td&gt; &lt;input type="radio" id="value4" name="description" value="0" checked&gt;Low sugar&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value4" name="description" value="0"&gt;Normal sugar&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value4" name="description" value="7"&gt;Quite high sugar&lt;/td&gt; &lt;td&gt; &lt;input type="radio" id="value4" name="description" value="10"&gt;High sugar&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="button" name="submit" value="Submit" onclick="javascript:addNumbers()" /&gt;Total = &lt;input type="text" id="answer" name="answer" value="" /&gt; &lt;section&gt; &lt;h2&gt;Your results:&lt;/h2&gt; &lt;div class="results" id="lowResult"&gt; &lt;p&gt;Your results show that you currently have a low risk of developing diabetes. However, it is important that you maintain a healthy lifestyle in terms of diet and exercise. &lt;/p&gt; &lt;/div&gt; &lt;div class="results" id="mediumResult"&gt; &lt;p&gt;Your results show that you currently have a medium risk of developing diabetes. For more information on your risk factors, and what to do about them, please visit our diabetes advice website at &lt;a href="http://www.zha.org.zd"&gt;http://www.zha.org.zd&lt;/a&gt;. &lt;p&gt; &lt;/div&gt; &lt;div class="results" id="highRisk"&gt; &lt;p&gt;Your results show that you currently have a HIGH risk of developing diabetes. [Your main risk factors are your BMI and your diet.] We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you. &lt;/div&gt; &lt;/section&gt;</code></pre> </div> </div> </p>