title: Form inputs and conditional javascript submit
body: <p>I have a function to sum values a form and compare with a another value.</p>
  
  <p><strong><a href="http://jsfiddle.net/La18Lcns/10" rel="nofollow">Fiddle HERE</a></strong>.</p>
  
  <p><strong>HTML :</strong></p>
  
  <pre><code>&lt;input class="fieldToValidate" name="option-quantity"&gt;
  &lt;input class="fieldToValidate" name="option-quantity"&gt;
  &lt;input class="fieldToValidate" name="option-quantity"&gt;
  &lt;input class="fieldToValidate" name="option-quantity"&gt;
  
  &lt;button type='button' id="button-cart"&gt;Add To Cart&lt;/button&gt;
  &lt;div class="errorQuantity"&gt;&lt;/div&gt;  
  </code></pre>
  
  <p><strong>JS :</strong></p>
  
  <pre><code>$('#button-cart').on('click', function()
  {
      var MaxSelectionNum = "7";
      var sum = 0;
  
      // Loop through all inputs with names that start
      // with "option-quantity" and sum their values
      $('input[name^="option-quantity"]').each(function()
      {
          var val = $(this).val() || 0;
          if(val != 0) {
            val = val.replace('.', '');
            val = val.replace(',', '.');
            val = parseFloat(val);
          }
  
          console.log(val);
          sum += val;
      });
  
      if (sum &lt; MaxSelectionNum)
      {
          $(".errorQuantity").html("Please select 7 meals").show();
      }
      else
      {
          $(".errorQuantity").html("You have select greater than 7: meal count:  " + sum).show();
      }
  });
  </code></pre>
  
  <p>This work, but i want to validate form before submit.</p>
  
  <p>If the sum &lt; 7, do not submit.</p>
  
  <p>How can i do it ?</p>
  
  <p>Thanks!</p>