Can't get form results from a mutiple select box

Hey everyone,
This seems really elementary and I have no clue what is wrong… I have
a form that has two multiple select boxes (using some javascript to
shift items from the left select box to the right box and vice versa)
and I want to grab what is in the second box after the user clicks
submit. It seems that each time I try to get that info in my controller,
it is returning nil. My form is as follows:

<%= form_tag :controller => ‘push’, :action => ‘index’, :type => ‘test’
-%>
Choose users to sync (<%= @address_num %> total users)

<% @address_array.each do |item| %>

<%= item %> <% end %> All Users (default)

<%= submit_tag ‘submit’ %>
<%= end_form_tag -%>

In my controller, I have:

@results = params[:sel2]

but it turns out that @results is nil every time!

Does anybody know what is going wrong??

Thanks!!

  • Jeff M.

I just figured out something… If I actually select something in the
second box, it works… but if there are multiple ones, it doesn’t. If
multiple items are selected, it only passes the first in the box… I
realize now that this is an HTML problem and I will have to just do a
bunch of googling, but if anyone knows how to overcome this, any help
would be appreciated.

Thanks,

  • Jeff M.

Hi, I’m just starting a project and want to implement the same
functionality. I would be very interested in knowing if/how you
resolved this issue. How are you handling loading both lists on page
load? That is, when you are editing an item, I would assume that you
would only load the “available” list with non-selected items and the
“selected” list with only those items previously selected.

TIA,
Henry

Jeff M. wrote:

Hey everyone,
This seems really elementary and I have no clue what is wrong… I have
a form that has two multiple select boxes (using some javascript to
shift items from the left select box to the right box and vice versa)
and I want to grab what is in the second box after the user clicks
submit. It seems that each time I try to get that info in my controller,
it is returning nil. My form is as follows:

<%= form_tag :controller => ‘push’, :action => ‘index’, :type => ‘test’
-%>
Choose users to sync (<%= @address_num %> total users)

<% @address_array.each do |item| %>

<%= item %> <% end %> All Users (default)

<%= submit_tag ‘submit’ %>
<%= end_form_tag -%>

pls try to name like this (rest is same)

All Users (default) In the controller pls try params[:sel2]||[]. I think this will give u the all the values of all the selected options in the select drop down.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs