8

So I have something that looks like this:

<script>
$(document).ready(function(){
  $("button.fadeMeOut").click(function(){
      var fadeID = $(this).attr('id');
      window.location.href = '@routes.Application.function(fadeID)';
  });
});
</script>

Of course this code will give a not found: value fadeID error. Is there a way for me to do something like this in Play Scala template?

cYn
  • 3,291
  • 6
  • 25
  • 43

2 Answers2

6

You can not mix Scala variables (server-side) with JS variables (client-side) as they are generated in quite distant environments.

Instead you can use for an example Play's javascriptRoutes like described in other question

Community
  • 1
  • 1
biesior
  • 55,576
  • 10
  • 125
  • 182
  • Also have a look at the documentation: http://www.playframework.com/documentation/2.1.0/ScalaJavascriptRouting – Carsten Jul 23 '13 at 18:00
4

You can insert the relative URL in place of '@routes.Application....etc'

So for example "/function/" + fadeID

If the route of @routes.Application.function is /function

Daniel Langer
  • 106
  • 1
  • 11
  • Even though I found a workaround to do what I needed in the original post, this solution is very close to my workaround. Accepted as the answer as this way works too. – cYn Jul 24 '13 at 21:48