faisal abdulai
faisal abdulai

Reputation: 3819

Using Play 2 framework drop down list with jQuery or JavaScript

I am new to play framework so please bear with me. Can some one explain to me how to access an item selected in a play 2 framework drop down list, using a jQuery function?

For example:

    <select class = "selectone">
@for(gesture <- gesturesList){
  <div class = "gesture" >  <option value = @gesture.id>
        @gesture.getName()
  </option>
  </div>} 
</select>

The above drop down list is populated by the following function:

public static Result gesture()
  {
  List <Gesture> gcet = Gesture.find.orderBy("name asc").findList();
  return ok(views.html.train.render(gcet)); 
}

I want to access the selected item using jQuery or maybe JavaScript. Any suggestion.

Upvotes: 1

Views: 857

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

Unless I misunderstood, that's nothing to do with Play, it's pure Jquery:

 //uses a class selector to get the selected value in the dropdown
 $(".selectone").val();

That said, you are adding a div in your select, it shouldn't be like that. Your code should be:

  <select class = "selectone">
  @for(gesture <- gesturesList){
      <option value = @gesture.id>
        @gesture.getName()
      </option>
  } 
  </select>

Upvotes: 1

Related Questions