Search code examples
javascriptscalaplayframeworkplayframework-2.3typesafe-activator

How to invoke Play framework Action from OnChange


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"
                        )

Solution

  • 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)