# How can I use checkboxes to change the value of an attribute?

**URL:** <https://metaruby.com/t/how-can-i-use-checkboxes-to-change-the-value-of-an-attribute/1680>\
**Category:** Ruby Questions\
**Created:** [May 7, 2018, 8:16pm UTC](https://metaruby.com/t/how-can-i-use-checkboxes-to-change-the-value-of-an-attribute/1680 "2018-05-07T20:16:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uriel1795](https://metaruby.com/letter_avatar_proxy/v4/letter/u/c77e96/32.png) [@Uriel1795](https://metaruby.com/u/Uriel1795)\
**Post date:** [May 7, 2018, 8:16pm UTC](https://metaruby.com/t/how-can-i-use-checkboxes-to-change-the-value-of-an-attribute/1680/1 "2018-05-07T20:16:57Z")

</div>

I am creating a Ruby on Rails application where it searches for certain classes according to their: model, session and year. Moreover, I need a check box to filter which class is being displayed on the screen.

The options include: VEX IQ and VRC. The way I was originally filtering this information was by doing the following:

```
<p><b> Saturday </b></p> 
<% Klass.where(days_of_week: 'Saturday', model: params[:chckBox], session: 'Spring', calendar_year: '2018').order('name asc').count('id') do |ksa| %>
   <li class="list"> <%= ksa.name %> </li>
<% end %> 

```

When I added a check box, I tried doing the following:

```
<%= check_box_tag(:chckBox)%>
<br>
<% if (params[:chckBox] == "true") %>
	<%= puts "Chceck box is checked" %>
<% elsif (params[:chckBox] == "false") %>
	<%= puts "Not checked" %>
<% end %>

```

I tried displaying the information to see what it would display, but it does not even do that. I need help haha. Please if you are able to understand what I am trying to do, just ask me again.

Thank you.

---

<div class="post-metadata">

**Author:** ![danielpclark](https://metaruby.com/user_avatar/metaruby.com/danielpclark/32/823_2.png) [@danielpclark](https://metaruby.com/u/danielpclark)\
**Post date:** [May 8, 2018, 6:50pm UTC](https://metaruby.com/t/how-can-i-use-checkboxes-to-change-the-value-of-an-attribute/1680/2 "2018-05-08T18:50:18Z")

</div>

[Unobtrusive JavaScript](https://blog.codeship.com/unobtrusive-javascript-via-ajax-rails/) is likely what you’re looking for. You can have a link or checkbox to a partial web page update with it.

If you don’t want to hit the server to update the page you’ll need to use JavaScript to update the page client side when a checkbox is selected. [How To - Toggle Hide and Show](https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp). This is more typical of filtering with checkboxes.
