Reputation: 503
I'm trying to have a date selection with datepicker, and then use this date for a query. I have a Movements table, and even if I select a date with an entry, the result is always 0.
How do I fix that ?
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" />
<p id="result"> Turnover: </p>
<script>
$("input").change(function(){
var currentDate = $( "#datepicker" ).datepicker( "getDate" );
document.getElementById("result").innerHTML= <%= Movement.where(:movementDate =>("currentDate")).sum("turnover")%>;
});
</script>
</p>
</body>
Upvotes: 0
Views: 275
Reputation: 18835
Sorry, but this is all wrong.
You need to send the date to your server via ajax, so that it can execute the query with the given date and then send the result back to the frontend.
In case you have, go here and have a look at jQuery and ajax requests: http://api.jquery.com/category/ajax/
Upvotes: 1