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?

2 Answers 2

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

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

1 Comment

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

1 Comment

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.

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.