title: jQuery - trying to do a function inside an if statement
body: <p>I'm trying to add some validation to a form.  I have a jQuery function that is doing exactly what I want:</p>
  
  <pre><code>      jQuery('#post').submit(function() {
                  if (jQuery("#set-post-thumbnail").find('img').size() &gt; 0) {
                      jQuery('#ajax-loading').hide();
                      jQuery('#publish').removeClass('button-primary-disabled');
                      return true;
                  }else{
                      alert("Please set a Featured Image!");
                      jQuery('#ajax-loading').hide();
                      jQuery('#publish').addClass('button-primary-disabled');
                      return false;
                  }
                  return false;
              });
  </code></pre>
  
  <p>However, I want to change it so that this function only runs if a radio button elsewhere on the page is selected.  So I tried this:</p>
  
  <pre><code>if (jQuery('#top').checked) {
        jQuery('#post').submit(function() {
                  if (jQuery("#set-post-thumbnail").find('img').size() &gt; 0) {
                      jQuery('#ajax-loading').hide();
                      jQuery('#publish').removeClass('button-primary-disabled');
                      return true;
                  }else{
                      alert("Please set a Featured Image!");
                      jQuery('#ajax-loading').hide();
                      jQuery('#publish').addClass('button-primary-disabled');
                      return false;
                  }
                  return false;
              });
      }
  </code></pre>
  
  <p>That doesn't work - the function doesn't get called even if #top is checked.  Can anyone explain why?  I'm used to PHP, and JavaScript often throws curveballs at me.</p>