title: How to pass an ajax date to jquery?
body: <p>I have a <code>datepicker</code>, and I want to use the picked date in a query in a Movements table, to retrieve corresponding turnover. But "<code>currentDate</code>" does not load with the <code>picked date</code> : I have a "invalid date" exception caught. How should I do it ? </p>
  
  <pre><code>$("#datepicker").change(function(){
          var currentDate = $( "#datepicker" ).datepicker( "getDate" );
          var wantedTO = &lt;%=Movement.where(:movementDate =&gt;Date.parse("currentDate")).sum("turnover")%&gt;;  
          $(document).ajaxComplete(function(){ $("#result").html("&lt;p&gt;Result here : &lt;/p&gt;" + wantedTO);     
          });             
      }); 
  </code></pre>
  
  <p>Note that if I replace </p>
  
  <pre><code>var wantedTO = &lt;%=Movement.where(:movementDate =&gt;Date.parse("currentDate")).sum("turnover")%&gt;;  
  </code></pre>
  
  <p>by </p>
  
  <pre><code>var wantedTO = &lt;%=Movement.where(:movementDate =&gt;Date.today).sum("turnover")%&gt;; 
  </code></pre>
  
  <p>it's giving me today's turnover. So I might not be so far !</p>
  
  <p>EDIT : 
  To be sure of the date format, I added a line </p>
  
  <pre><code> var dateString = $.datepicker.formatDate("yy-mm-dd", currentDate);
  </code></pre>
  
  <p>And checked OK that if I put a manual date in that format then, it's working. It seems that it's a problem of how to pass this variable, but I can't fix it. Any idea ? </p>