# Check box value in array

**URL:** <https://www.ruby-forum.com/t/check-box-value-in-array/105063>\
**Category:** Rails\
**Created:** [May 25, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/check-box-value-in-array/105063 "2007-05-25T12:29:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@amin](https://www.ruby-forum.com/u/amin)\
**Post date:** [May 25, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/check-box-value-in-array/105063/1 "2007-05-25T12:29:18Z")

</div>

Hi guys,  
I have a group of check box in rails page.  
check box Code as below:  
\<% for count in @total\_cellno %\>  
  
\<% end %\>

I want to receive the selected value in my controller model.

@selected\_box \<\< params[“checkbox”]  
I guess that it provides values in a array.  
But @selected\_box contains only one selected value.  
How can i capture all checked value in a array?  
Any idea?  
Please help me…

Amin

---

<div class="post-metadata">

**Author:** ![amin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@amin](https://www.ruby-forum.com/u/amin)\
**Post date:** [May 25, 2007, 1:37pm UTC](https://www.ruby-forum.com/t/check-box-value-in-array/105063/2 "2007-05-25T13:37:30Z")

</div>

if you name your checkboxes like this

you’ll get what you like

Parameters: {“commit”=\>“Do”, “checkbox”=\>{“1”=\>“1”, “3”=\>“1”}}

hint: there is a check\_box\_tag() helper !

Marcel

---

<div class="post-metadata">

**Author:** ![amin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@amin](https://www.ruby-forum.com/u/amin)\
**Post date:** [May 28, 2007, 6:04am UTC](https://www.ruby-forum.com/t/check-box-value-in-array/105063/3 "2007-05-28T06:04:02Z")

</div>

lanzm wrote:

> if you name your checkboxes like this
> 
> you’ll get what you like
> 
> Parameters: {“commit”=\>“Do”, “checkbox”=\>{“1”=\>“1”, “3”=\>“1”}}
> 
> hint: there is a check\_box\_tag() helper !
> 
> Marcel

Hi Marcel,  
I use check\_box\_tag for check box ( according to ur hints)

\<% for count in @total\_cellno %\>  
\<%= check\_box\_tag(“checkbox”, value = count, checked = false) %\>  
\<% end %\>

and in controller model I use following code to retrive the value in  
Hash:  
@total = params[“checkbox”]  
In @total only one value is stored.  
Where is the problem? please take a hand. Thx in advanced.

Amin

---

<div class="post-metadata">

**Author:** ![amin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@amin](https://www.ruby-forum.com/u/amin)\
**Post date:** [May 28, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/check-box-value-in-array/105063/4 "2007-05-28T14:01:11Z")

</div>

> I use check\_box\_tag for check box ( according to ur hints)
> 
> \<% for count in @total\_cellno %\>  
> \<%= check\_box\_tag(“checkbox”, value = count, checked = false) %\>  
> \<% end %\>

I think you won’t get more than one if you name them all the same.  
Give it a name as I explained:

\<%= check\_box\_tag(“checkbox[\<%=count.to\_s%\>]”, value = count,  
checked = false) %\>

or

\<%= check\_box\_tag(“checkbox[]”, value = count, checked = false) %\>

–  
marcel
