title: Multiple checkbox jquery calculation
body: <p>here is my test code to calculate a multi choice quiz.</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;Multiple checkbox calculation&lt;/title&gt;
          &lt;style&gt;
              div {
                  color: red;
                  font-size: 35px;
              }
          &lt;/style&gt;
          &lt;script src="http://code.jquery.com/jquery-1.6.1.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              $(document).ready(function() {
  
  
                  $("input[type=checkbox]").click(function() {
  
                      var total = 0;
                      $("input[type=checkbox]:checked").each(
  
                      function() {
  
                          total += parseInt($(this).val());
  
                      });
  
                      $("#total").html("tatal:" + total);
                  });
  
              });
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;table&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th scope="col" width="50px"&gt;No:&lt;/th&gt;
                      &lt;th scope="col" width="40px"&gt;A&lt;/th&gt;
                      &lt;th scope="col" width="40px"&gt;B&lt;/th&gt;
                      &lt;th scope="col" width="40px"&gt;C&lt;/th&gt;
                      &lt;th scope="col" width="40px"&gt;D&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;th&gt;1&lt;/th&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared00" name="fieldMark[correct00]" value="1"&gt;
                          &lt;label for="squared00" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared01" name="fieldMark[correct01]" value="-1"&gt;
                          &lt;label for="squared01" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared02" name="fieldMark[correct02]" value="-1"&gt;
                          &lt;label for="squared02" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared03" name="fieldMark[correct03]" value="-1"&gt;
                          &lt;label for="squared03" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;2&lt;/th&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared10" name="fieldMark[correct10]" value="1"&gt;
                          &lt;label for="squared10" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared11" name="fieldMark[correct11]" value="-1"&gt;
                          &lt;label for="squared11" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared12" name="fieldMark[correct12]" value="-1"&gt;
                          &lt;label for="squared12" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared13" name="fieldMark[correct13]" value="-1"&gt;
                          &lt;label for="squared13" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;3&lt;/th&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared20" name="fieldMark[correct20]" value="1"&gt;
                          &lt;label for="squared20" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared21" name="fieldMark[correct21]" value="-1"&gt;
                          &lt;label for="squared21" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared22" name="fieldMark[correct22]" value="-1"&gt;
                          &lt;label for="squared22" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared23" name="fieldMark[correct23]" value="-1"&gt;
                          &lt;label for="squared23" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;4&lt;/th&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared30" name="fieldMark[correct30]" value="1"&gt;
                          &lt;label for="squared30" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared31" name="fieldMark[correct31]" value="-1"&gt;
                          &lt;label for="squared31" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared32" name="fieldMark[correct32]" value="-1"&gt;
                          &lt;label for="squared32" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared33" name="fieldMark[correct33]" value="-1"&gt;
                          &lt;label for="squared33" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;5&lt;/th&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared40" name="fieldMark[correct40]" value="1"&gt;
                          &lt;label for="squared40" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared41" name="fieldMark[correct41]" value="-1"&gt;
                          &lt;label for="squared41" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared42" name="fieldMark[correct42]" value="-1"&gt;
                          &lt;label for="squared42" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input type="checkbox" class="css-checkbox" id="squared43" name="fieldMark[correct43]" value="-1"&gt;
                          &lt;label for="squared43" class="css-label"&gt;&lt;/label&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;div id="total"&gt;&lt;/div&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>this code for auto calculation for multiple choice quiz. only option "A" is correct for each 5 question other all options is incorrect. here is my requirements.</p>
  
  <ul>
  <li>when user clicks on only option "correct" for any question number it adds point 1 to the total.</li>
  <li>when user clicks on only option "incorrect" for any question will add point -1 to the total.</li>
  <li>when user clicks on both option "correct" and "incorrect" for any question number it adds point -1 to the total. for example user clicks all checkbox for question 1 it should add only -1 to the total (in example above it is -2 which is = 1-1-1-1.) ie. if a user checked all the checkbox in the above example it will get total:-10. But my requirement is to show only -5. ie = -1-1-1-1-1.</li>
  </ul>
  
  <p>thanks in advance..</p>