0

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>

2
  • Are you trying to use the JavaScript variable in a Ruby method? That's not going to work. Take a look at the generated HTML page. Commented Feb 14, 2013 at 17:59
  • Thanks for your answer. But then, how can I use the date in my query ? Commented Feb 14, 2013 at 18:18

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

Now I have a problem with the ajaxComplete function... But still, I improved thanks to your answer ! ;-) stackoverflow.com/questions/14909306/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.