user1248868
user1248868

Reputation: 1

How do I default a selection using Dropkick in the HTML?

I want to pre-select a certain option in a dropdown list and want to use the "selected" parameter in HTML to select it. Is this possible?

                        <option value="@cat.ID" 
                            @if(cat.ID == 2){
                                @: selected );
                            }
                        >@cat.Category</option>

Upvotes: 0

Views: 233

Answers (1)

Rahul Gupta
Rahul Gupta

Reputation: 10141

To select a default option, you can do this:

var elm = new Dropkick("#select");

// Select by index
elm.select(4); //selects & returns 5th item in the list

// Select by value
elm.select("AL"); // selects & returns option with the value "AL"

Reference documentation: http://dropkickjs.com/api.html#method-select

Upvotes: 0

Related Questions