views:

27

answers:

1

I have a simple drop down box on a page with the below code:

  <p>
    <%= f.label "Group" %><br />
    <%=  select("employee", "group_id", Group.all.collect {|p| [ p.name, p.id ] }, { :include_blank => true })%>
  </p>

  <div id="employees">
     <!--this will be filled with ajax request-->
  </div>

it shows Groups to the user. What I'd like is to have a div next to this drop down that displays number of employees that belong to a group. I get this number by:

Groups.employees.count

but I don't know how this would work with ajax as everytime the drop down changes i'll have to go back to the server to get this number and then update the div.

I can use jQuery if need be.

A: 

Possibly: write all of the groups with all of the counts into the HTML or into a JavaScript variable, and use JavaScript simply to control which one of the counts is visible at any one time.

Justice
I wanted to do this the ajax way but that's a good idea as well. If I cant get this to work then I will try your suggestion. thanks
Patrick