title: How to terminate javascript function if condition is met
body: <p>Hello how can i terminate function daterange when param vale is not equal to "date"</p>
  
  <p>because if condition is met and function daterange is executed the function still running even if param value is not equal to "date"
  Note my code is inside asp update panel</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  &lt;script type="text/javascript"&gt;
                                  $(document).ready(function (e) {
                                      $('.search-panel .dropdown-menu').find('a').click(function (e) {
                                          e.preventDefault();
                                          var param = $(this).attr("href").replace("#", "");
                                          var concept = $(this).text();
                                          $('.search-panel span#search_concept').text(concept);
                                          $('[id$=hdnSearchParam]').val(param);
                                          if (param == "date") {
                                              $(function daterange () {
                                                  $("#&lt;%= txtsearch.ClientID %&gt;").daterangepicker({
                                                      locale: {
                                                          format: 'DD/MMM/YYYY'
                                                      }
                                                  });
                                              });
                                          }
                                          else { //terminate the function }
  
                                      });
                                  });
  
                                  //Re-Create for on page postbacks
                                  var prm = Sys.WebForms.PageRequestManager.getInstance();
                                  prm.add_endRequest(function daterange() {
                                      $('.search-panel .dropdown-menu').find('a').click(function (e) {
                                          e.preventDefault();
                                          var param = $(this).attr("href").replace("#", "");
                                          var concept = $(this).text();
                                          $('.search-panel span#search_concept').text(concept);
                                          $('[id$=hdnSearchParam]').val(param);
                                          if (param == "date") {
                                              $(function () {
                                                  $("#&lt;%= txtsearch.ClientID %&gt;").daterangepicker({
                                                      locale: {
                                                          format: 'DD/MMM/YYYY'
                                                      }
                                                  });
                                              });
                                          }
                                          else { //terminate the function }
                                      });
                                  });
                              &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>