2

I am newbie to Play Framework with Scala environment.I would like to invoke Controller Action method from @select()~dropdown OnChange.

How I invoke from Button

<a href="@routes.Application.cancel()"><span>Cancel</span></a> 

What I actually need

I need to invoke my Action from drop down OnChange method.please help me to accomplish this task.

Edit

@select(
   userMapForm("department"),
   DepartmentList,//set values from DB
   '_default -> "-- Select Department --",
    'onChange->"//invoke Action from here"
                        )
Jamal
  • 976
  • 2
  • 14
  • 39
  • Please show us some code! In general you'd do it like you used the route `@routes.Application.cancel()` in your link/button. – Kris Oct 06 '15 at 14:49
  • I need to invoke `Action` for example `@routes.Application.cancel()` in Drop down `OnChange` like how we invoked that action from `` tag – Jamal Oct 06 '15 at 14:56
  • @Kris I edited my code please have a check on it. – Jamal Oct 06 '15 at 15:01
  • It looks like there is a very similar question: http://stackoverflow.com/questions/15552218/using-the-playframework-scala-select-template-onchange-event. Does it help? – Kris Oct 06 '15 at 15:25
  • No It doesn't have the answer – Jamal Oct 06 '15 at 15:32

1 Answers1

2

You can to do this with trivial javascript.

@select(
   userMapForm("department"),
   DepartmentList,//set values from DB
   '_default -> "-- Select Department --")


<script>
  document.getElementById("department").addEventListener("change", funciton(){
    location.replace("@routes.Application.cancel()");
  });
</script>

You could use jQuery to simplify it (or other javascript framework)

Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46
  • Thanks dude,it is working fine.I just modified it with below code `@select( 'onChange->"methodForTest()") function methodForTest(){ location.replace("@routes.Application.cancel()"); };` – Jamal Oct 07 '15 at 06:48