title: Closing Bootstrap modal onclick
body: <p>I am using a Bootstrap modal for users to choose product options before adding an item to their cart. I've used them before in this scenario with no issues but this one isn't closing as expected. </p>
  
  <p>When a user clicks on the 'Add To Cart' button, a few things happen and I'm thinking the problem lies there. First, some script checks that certain fields have been completed correctly. Once that is all verified, the user is allowed to add the item to their cart at which point another window pops up for them to review their cart content and choose to either proceed to cart or continue where they left off.</p>
  
  <p>I'd like the modal window to close once the 'Add To Cart' button is clicked, after the script has verified all fields are filled out as necessary. Currently, it just sits there and if the user chooses to continue where they left off and the other window closes, it's still there.</p>
  
  <p>HTML for modal:</p>
  
  <pre><code>   &lt;a type="button" class="btn btn-small btn-primary" href="#product-options" data-toggle="modal"&gt;&lt;i class="icon-shopping-cart icon-white"&gt;&lt;/i&gt;&amp;nbsp;Buy This!&lt;/a&gt;                                        
         &lt;div class="modal hide fade" id="product-options"&gt;                    
              &lt;div class="modal-header center"&gt;
                    &lt;a class="close modal-close l-m" data-dismiss="modal" aria-hidden="true"&gt;x&lt;/a&gt;
                    &lt;h2 class="modal-header"&gt;When, Where and How?&lt;/h2&gt;
               &lt;/div&gt;   
               &lt;div class="modal-body ll-m r-m"&gt;
                   &lt;h5 class="top-m"&gt;Please Choose From Delivery Options:&lt;/h5&gt;                                                                                  
                       &lt;label for="Standard"&gt;
                           &lt;input id="Standard" type="radio" name="properties[Delivery]" value="Standard Shipping" /&gt;
                           &lt;h5&gt;Standard Shipping&lt;/h5&gt;&lt;br /&gt;
                               &lt;p&gt;&lt;small&gt;Earliest Date of Delivery: 
                                   &lt;span id="delivery-date"&gt;&lt;/span&gt;&lt;/small&gt;&lt;/p&gt;
                       &lt;/label&gt;
                       &lt;label for="datepicker" style="margin-left: 18px;"&gt;Desired Delivery Date: &lt;/label&gt;
                            &lt;input id="datepicker" type="text" placeholder="ex. 01/01/2013" name="properties[Delivery Date]" style="margin-left: 18px;" readonly/&gt;   
                            &lt;h5&gt;Please verify your age:&lt;/h5&gt;
                                &lt;input type="hidden" name="properties[age_verified]" value=""/&gt;                             
                                &lt;label for="age_verification"&gt;
                                &lt;input id="age_verification" type="checkbox" name="properties[Age Verified]" value="Yes" required="required" /&gt;
                                &lt;p class="center-text"&gt;&lt;small&gt;This gift contains alcohol. By checking this box you certify you are 21yrs of age or older. An adult signature with ID will be required upon delivery.&lt;/small&gt;&lt;/p&gt;
                                &lt;/label&gt;      
               &lt;/div&gt; &lt;!-- end of modal body --&gt; 
  
              &lt;div class="modal-footer"&gt; 
                  &lt;div class="btn-group fr"&gt;
                     &lt;button class="btn btn-small" data-dismiss="modal" aria-hidden="true"&gt;Cancel&lt;/button&gt;                       
                     &lt;button href="#" id="addtocart" class="btn btn-small btn-warning" onclick="return validateShipping();"&gt;Add To Cart&lt;/button&gt;                       
                 &lt;/div&gt;                  
             &lt;/div&gt;&lt;!-- end of modal footer --&gt;           
         &lt;/div&gt; &lt;!-- end of modal --&gt;
  </code></pre>
  
  <p>SCRIPT to check fields: </p>
  
  <pre><code>&lt;script&gt;
  // Hides shipping info fieldset if ship to billing is checked
  $(function () {
      $("#ship_to_billing").change(function () {
          if ($(this).is(":checked")) $("#shipping_info").hide();
          else $("#shipping_info").show();
      });
  });
  
  // Validates address fields are filled out unless ship to billing is checked...   
  function validateShipping() {
      if (!$("#ship_to_billing").is(":checked")) {
          var inputs = $("#shipping_info input");
          var ready = true;
          inputs.each(function () {
              if ($(this).val() == '') {
                  ready = false;
                  return false;
              }
          });
          if (!ready) {
              alert("Oops! Something's missing! Either choose 'Ship to My Billing Address' or all of the Recipient Name and Shipping Address fields must be completed. Thanks!");
              return false;
          }
      }
          // Makes sure age verification is checked 
          if (!$('#age_verification').is(':checked')) {
              alert("Please verify you are 21 years of age or older.");
              return false;       
          }    
        // Confirms province is allowed for wine shipping     
            var states = ["AK", "AZ", "CA", "CO", "CT", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "LA", "ME", "MD", "MI", "MN", "MO", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OR", "SC", "TN", "TX", "VT", "VA", "WA", "WV", "WI", "WY", ""];
                   if ($.inArray($("#address_province").val().toUpperCase(), states) &lt;0) {
                   alert("Shipping gifts containing alcohol to this state is prohibited by law. Please choose another item.");
                   return false;       
          }
   return true;
  }  
  
  &lt;/script&gt;
  </code></pre>