# Can't get form results from a mutiple select box

**URL:** <https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547>\
**Category:** Rails\
**Created:** [April 23, 2008, 1:16am UTC](https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547 "2008-04-23T01:16:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 23, 2008, 1:16am UTC](https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547/1 "2008-04-23T01:16:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 23, 2008, 1:38am UTC](https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547/2 "2008-04-23T01:38:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [November 27, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547/3 "2008-11-27T16:05:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [November 28, 2008, 6:45am UTC](https://www.ruby-forum.com/t/cant-get-form-results-from-a-mutiple-select-box/135547/4 "2008-11-28T06:45:50Z")

</div>

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.
