title: how to stop form submit and throw error jquery
body: <p>Hi I have button in popup that submits the payment gateway information. All I want is when payment method (radio button) or accept terms (check box) are not checked i have to throw error, if any one is choosed then throw error to check another and if both are checked then open new mini browser. where I have used AJAX to submit these values .</p>
  
  <pre><code>$(document).ready(function() {
  
  
      $(document).on("mouseover", ".imgpayment", function() {
          $(this).parent().addClass("paymenthover");
      });
  
      $(document).on("mouseout", ".imgpayment", function() {
          $(this).parent().removeClass("paymenthover");
      });
  
      $(document).on("click", ".the-terms", function() {
          if ($(this).is(":checked")) {
              $("table#paymenttable td").each(function() {
                  if ($(this).hasClass("paymentclick")) {
                      $(this).removeClass("paymentclick");
                  }
              });
              if ($("#policyAgree").prop('checked') == true) {
                  $("#submitBtn").removeAttr("disabled");
              } else {
                  $("#paymentError").html('&lt;span class="disablebtnInfo" id="msg" style="display:block;margin-left: 40%;"&gt;&lt;span class="error_sign"&gt;!&lt;/span&gt;&amp;nbsp;&lt;span id="errmsg"&gt;Agree terms and condition.&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;');
  
              }
              $(this).parent().addClass("paymentclick");
          } else {
              $("#paymentError").html('&lt;span class="disablebtnInfo" id="msg" style="display:block;margin-left: 40%;"&gt;&lt;span class="error_sign"&gt;!&lt;/span&gt;&amp;nbsp;&lt;span id="errmsg"&gt;Agree terms and condition.&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;');
              $("#submitBtn").attr("disabled", "disabled");
          }
      });
  
  
      $(document).on("click", ".imgpayment", function() {
          $("table#paymenttable td").each(function() {
              if ($(this).hasClass("paymentclick")) {
                  $(this).removeClass("paymentclick");
              }
          });
          if ($("#policyAgree").prop('checked') == true) {
  
          } else {
              $("#paymentError").html('&lt;span class="disablebtnInfo" id="msg" style="display:block;margin-left: 40%;"&gt;&lt;span class="error_sign"&gt;!&lt;/span&gt;&amp;nbsp;&lt;span id="errmsg"&gt;Agree terms and condition.&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;');
  
          }
          $(this).parent().toggleClass("paymentclick");
          $(this).parent().find(".the-terms").prop('checked', true);
          checkterms();
      });
  
  
  });
  
  
  $(document).on("click", "#policyAgree", function() {
      if ($(this).prop('checked') == true) {
          checkterms();
      } else {
          $("#submitBtn").attr("disabled", 'disabled');
      }
  
  });
  
  function checkterms() {
      if ($(".the-terms").is(":checked") &amp;&amp; $("#policyAgree").is(":checked")) {
          $("#submitBtn").removeAttr("disabled");
      } else {
          $("#submitBtn").attr("disabled");
      }
  }
  </code></pre>
  
  <p>and html: </p>
  
  <pre><code>&lt;tr id="paymentmethod"&gt;
      &lt;td&gt;
          &lt;input type="radio" name="payment" value="paypal" class="the-terms" required&gt;
          &lt;img src='&lt;?php echo base_url() . ' contents/images/paypal.png '; ?&gt;' class="imgpayment" style="height: 40px;"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;
          &lt;input type="radio" name="payment" value="esewa" class="the-terms" required&gt;
          &lt;img src='&lt;?php echo base_url() . ' contents/images/esewa.png '; ?&gt;' class="imgpayment" style="height: 40px;"&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php } ?&gt;
  &lt;tr&gt;
      &lt;td style="height: 50px;"&gt;
          &lt;input type="radio" name="payment" value="counterPay" class="the-terms" required&gt;
          &lt;span class="imgpayment" style="font-weight: bold"&gt; Cash On Arrival &lt;/span&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;div id="action"&gt;
      &lt;input id="type" type="hidden" name="mini" value="mini" /&gt;
      &lt;input id="paykey" type="hidden" name="paykey" value="10" /&gt;
      &lt;input type="button" id="popupBtn" value="Back" onclick="backbutton()" class="backBtnPayment" /&gt;
      &lt;span id="paymentError" style="color:#0d0daf;font-size: 12px;float: left;"&gt;&lt;?php if(!empty($msgs)){ echo $msgs; } ?&gt;&lt;/span&gt;
      &lt;input type="submit" id="submitBtn" value="Next" class="payment" disabled style="float: right;"&gt;
  &lt;/div&gt;
  </code></pre>