0

I'm having trouble trying to pass an "id" on-click to my controller. It never actually gets past jsRoutes to alert. The idea was onclick, add a border style, and then send the item that was clicked (the id). Any help would be greatly appreciated.

<script>
$('.select_it').on('click', function(e){
    var id = $(this).attr('id');

    $(this).toggleClass('myState');
    jsRoutes.controllers.Builder.selectOption(id).ajax({});

    alert(id);
        });
</script>

ROUTES FILE:

PUT /category/option/:id        controllers.Builder.selectedOption(id:Long)

GET     /assets/javascripts/routes  controllers.Builder.javascriptRoutes()

JAVASCRIPT ROUTES:

public static Result javascriptRoutes() {
    response().setContentType("text/javascript");
    return ok(
      Routes.javascriptRouter("jsRoutes",
        controllers.routes.javascript.Builder.selectedOption()
      )
  );
}
jb8893
  • 43
  • 1
  • 6
  • Ahhh figured it out. When you clicked an element, the .css class would change thus breaking you out of the function. Fixed by adding both classes. ('.select_it, .myState').on('click', function(e){ – jb8893 Oct 11 '13 at 05:01
  • Just answer yourself and you wil be able to accept it in two days, probably this tip will help others in future – biesior Oct 11 '13 at 22:59

0 Answers0