title: How to get value from text input on blur of field
body: <p>I'm trying to write some Javascript to get the value from two text inputs, which should be fairly straightforward.  But something is amiss.  Here is my code:</p>
  
  <pre><code>&lt;script&gt;
      jQuery(function() {
          jQuery('#fromPicker, #toPicker').datepicker({ dateFormat : 'yy-mm-dd' });
  
          jQuery('#submit').attr('disabled', 'disabled');
  
          jQuery('#toPicker').on('blur', function() {
              var fromDate = jQuery('#fromPicker').val();
              var toDate = jQuery('#toPicker').val();
              console.log(toDate);
  
              if (fromDate !== '' &amp;&amp; toDate !== '') {
                  if (isValidDate(fromDate) &amp;&amp; isValidDate(toDate)) {
                      jQuery('#submit').removeAttr('disabled');
                  } else {
                      alert('You must enter dates in the format "yyyy-mm-dd"');
                  }
              } 
          });
      });
  
      function isValidDate(dt) {
          if (dt.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)) {
              return true;
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>When I <code>console.log(toDate)</code> however, I get an empty string.  But if I do another <code>blur</code> event again (focus and unfocus the field with the data still in it), I get the correct value.  Any ideas why it doesn't work the first time?</p>
  
  <p>The two text inputs have IDs of <code>#fromPicker</code> and <code>#toPicker</code> and are jQueryUI datepickers.  </p>
  
  <p>SOLUTION:</p>
  
  <p>What ultimately did what I wanted was this:  </p>
  
  <blockquote>
    <p>
        jQuery(function() {
            jQuery('#fromPicker, #toPicker').datepicker({
                dateFormat : 'yy-mm-dd'
            });</p>
  
  <pre><code>    jQuery('#submit').on('click', function() {
          var fromDate = jQuery('#fromPicker').val();
          var toDate = jQuery('#toPicker').val();
  
          if (fromDate !== '' &amp;&amp; toDate !== '') {
              if (isValidDate(fromDate) &amp;&amp; isValidDate(toDate)) {
                  // do nothing
              } else {
                  alert('You must enter dates in the format "yyyy-mm-dd"');
                  return false;
              }
          } else {
              return false;
          }
      });
  });
  
  function isValidDate(dt) {
      if (dt.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)) {
          return true;
      }
  } &lt;/script&gt;
  </code></pre>
  </blockquote>