# How to get the checkbox value

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238>\
**Category:** Rails\
**Created:** [May 21, 2008, 9:02am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238 "2008-05-21T09:02:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaurav\_dua123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bb73d2/32.png) [@gaurav\_dua123](https://www.ruby-forum.com/u/gaurav_dua123)\
**Post date:** [May 21, 2008, 9:02am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238/1 "2008-05-21T09:02:58Z")

</div>

Hi i am trying to made a grossery application…  
here in this application i am using checkbox for the items.  
suppose there are 5 items in the page for example…  
in the first checkbox let’s say tea,  
2 checkbox Coffee…  
3 Checbox Rice  
$ checkbox Wheat

suppose a user select any of the one item which he want to purchase…

i have all these item in the item table… so by default the ruby will  
generate the item id…

now what i want is that…  
if a user select suppose tea to order by checking the tea checkbox…  
now i want the item id of tea for the furhter use in my order table so  
that the user will complete his order…

---

<div class="post-metadata">

**Author:** ![gaurav\_dua123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bb73d2/32.png) [@gaurav\_dua123](https://www.ruby-forum.com/u/gaurav_dua123)\
**Post date:** [May 21, 2008, 10:00am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238/2 "2008-05-21T10:00:25Z")

</div>

If your checkbox is named “coffee”, and the user submits the form  
containing it, the result will be in params[:coffee]. You’ll get params  
for all checkboxes in your form and the checked ones will have a “1” and  
the unchecked a “0”.

---

<div class="post-metadata">

**Author:** ![gaurav\_dua123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bb73d2/32.png) [@gaurav\_dua123](https://www.ruby-forum.com/u/gaurav_dua123)\
**Post date:** [May 23, 2008, 11:21am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238/3 "2008-05-23T11:21:41Z")

</div>

Thorsten M. wrote:

> If your checkbox is named “coffee”, and the user submits the form  
> containing it, the result will be in params[:coffee]. You’ll get params  
> for all checkboxes in your form and the checked ones will have a “1” and  
> the unchecked a “0”.

how i will do that if a checkbox is selected it is “1” and the unchecked  
is “0”…  
can you please give the code with an example…

---

<div class="post-metadata">

**Author:** ![gaurav\_dua123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bb73d2/32.png) [@gaurav\_dua123](https://www.ruby-forum.com/u/gaurav_dua123)\
**Post date:** [May 21, 2008, 10:30am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238/4 "2008-05-21T10:30:00Z")

</div>

> **[Simple & Awesome Rails Form](http://teapoci.blogspot.com/2008/05/simple-awesome-rails-form.html)**
>
> How to create Simple, fast and awesome rails form in your rhtml or html.erb ? the answer for now is Super\_In\_Place\_Controls & I tested in R...

Reinhart

---

<div class="post-metadata">

**Author:** ![gaurav\_dua123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bb73d2/32.png) [@gaurav\_dua123](https://www.ruby-forum.com/u/gaurav_dua123)\
**Post date:** [May 23, 2008, 11:24am UTC](https://www.ruby-forum.com/t/how-to-get-the-checkbox-value/138238/5 "2008-05-23T11:24:44Z")

</div>

after selected the multiple checkbox we have to store the value in the  
order table as well as in the line\_order table…

i am able to solve for the single checkbox…

the value is added into the database but how i will check if a user  
order for multiple product…
