Note that there are some explanatory texts on larger screens.

plurals
  1. POQuiz - Counts Radio Button Values
    primarykey
    data
    text
    <p>I'm trying to create a Quiz for a Spanish class. I have little experience with JavaScript, but am fairly proficient with html and CSS. I have a question and followed by three radio buttons with answers. There are two incorrect answers and a correct answer. I have 45 questions total.</p> <pre><code>&lt;form name="quiz" method="post" name="buttons" id="form" onsubmit="return totalVal()"&gt; &lt;li&gt;&lt;div class="question"&gt;¿Quién detestan la nueva casa?&lt;/div&gt;&lt;/li&gt; &lt;input id="answer" type="radio" name="group1" value="wrong"&gt; Josh&lt;br&gt; &lt;input id="answer" type="radio" name="group1" value="wrong"&gt; Amanda&lt;br&gt; &lt;input id="answer" type="radio" name="group1" value="correct"&gt; Josh y Amanda&lt;hr&gt; &lt;li&gt;&lt;div class="question"&gt;¿Quién es señor Dawes?&lt;/div&gt;&lt;/li&gt; &lt;input id="answer" type="radio" name="group2" value="wrong"&gt;Un familia amigo&lt;br&gt; &lt;input id="answer" type="radio" name="group2" value="wrong"&gt;Un gato&lt;br&gt; &lt;input id="answer" type="radio" name="group2" value="correct"&gt;Un amable joven de la agencia de bienes raíces&lt;hr&gt; &lt;li&gt;&lt;div class="question"&gt;¿Quién qué sus buscan?&lt;/div&gt;&lt;/li&gt; &lt;input id="answer" type="radio" name="group3" value="wrong"&gt;Josh&lt;br&gt; &lt;input id="answer" type="radio" name="group3" value="wrong"&gt; Petey&lt;br&gt; &lt;input id="answer" type="radio" name="group3" value="correct" &gt;Josh y Petey&lt;hr&gt; &lt;button class="submit" onclick="showTotalvalue();" type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt; </code></pre> <p>I want to use some basic Javascript to count all the "correct" radio button values and output to a new page or alert box that displays after the user clicks submit.</p> <p>I found this in my research. In my googling, I haven't been able to find a snippet of code that counts the "correct" values. The link above is the closest I've gotten. I attached the JavaScript that I changed to fit my situation from the suggestion on the other post.</p> <pre><code>totalVal = 0; // calculate the total number of corrects clicked for (y = 0; y = incorrectOfQuestion; y++) { var questionNo = document.getElementsByName("questions" + y); for (i = 0; i &lt; questionNo.length; i++) { if (document.myform.questions[i].checked == true) { totalVal = totalVal + parseInt(document.myform.questions[i].value, 45); } } } </code></pre> <p>Any assistance is greatly appreciated as I am in a time crunch! Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload