title: Calling a JQuery function inside a condition
body: <p>I'm new to JS and JQuery and I'm trying implement the following functionality.</p>
  
  <p>I have a form which has multiple inputs, each having its individual validation. These validations have been implemented inside one function.</p>
  
  <pre><code>function checkUpload() {
      var flagu1=0;
      var bookname = document.getElementById("title").value;
  
      var flagu2=0;
      .....
      .....
      var flagu6=0;
  
      if( flagu1==0 &amp;&amp; flagu2==0 &amp;&amp; flagu3==0 &amp;&amp; flagu4==0 &amp;&amp; flagu6==0 )
          return true;
      else 
          return false;
  }
  </code></pre>
  
  <p>This validation function is executed when a user clicks on the following button:</p>
  
  <pre><code>&lt;button class="btn btn-secondaryup" name="submit" value="Upload" id="submitmeup" data-loading-text="UPLOADING..." onclick="clearBox('uploaderror')" type="submit" style="width:100%"&gt;UPLOAD&lt;/button&gt;
  </code></pre>
  
  <p>Now I'm trying to implement Bootstap's 'loading state button' in this. The functionality would work like this:</p>
  
  <p>When a user clicks on the button, the front-end validation function is called. Once the validation function (checkUpload()) returns true, the following JQuery function should be called.</p>
  
  <pre><code>&lt;script&gt;
         $('#submitmeup').click(function() {
         var $btn = $(this);
         $btn.button('loading');
         setTimeout(function () {
         $btn.button('reset');
         }, 5000);
         });
  &lt;/script&gt;
  </code></pre>
  
  <p>The trick is that the button loading function has to be called only after the checkUpload function returns true. How do I implement this?</p>