tags:

views:

21

answers:

2

I have a question.Here is the code!

  f.select(:departments,Department.all.collect{|c|[c.name,c.id]},{},:size=>10,:multiple => ture)
   class Emergency
     has many :departments
   end

the html source like this:

<select id="emergency_departments" multiple="multiple" name="emergency[departments][]" size="10"><option value ="">""</option>....</select>

now I want to get the default selected tag , who can tell me how ?

A: 

You want to find the value of the option selected? Is that right?

If so, and you know your way around a bit of JQuery, this is how you do it:

$("#emergency_departments option:selected").val()
Ganesh Shankar
A: 

Now I know the question , i used the tag "collection_select" to solve this problem.Its method like this, f.collection_select(:departments,Department.all,:id,:name,)

Small Wolf