# Setting session variable with a checkbox

**URL:** <https://www.ruby-forum.com/t/setting-session-variable-with-a-checkbox/109975>\
**Category:** Rails\
**Created:** [July 20, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/setting-session-variable-with-a-checkbox/109975 "2007-07-20T21:09:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [July 20, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/setting-session-variable-with-a-checkbox/109975/1 "2007-07-20T21:09:11Z")

</div>

Hi:

Is there a way to set a session variable in a check box that’s not in a  
form nor linked to a controller? The checkbox value would also be the  
value of the session variable I want it to set. I assume I have to put  
this in a form. Any suggestions?

Thanks very much in advance!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [July 22, 2007, 10:14am UTC](https://www.ruby-forum.com/t/setting-session-variable-with-a-checkbox/109975/2 "2007-07-22T10:14:34Z")

</div>

Mike D. wrote:

> Hi:
> 
> Is there a way to set a session variable in a check box that’s not in a  
> form nor linked to a controller? The checkbox value would also be the  
> value of the session variable I want it to set. I assume I have to put  
> this in a form. Any suggestions?
> 
> Thanks very much in advance!
> 
> Mike

just an idea, but you could do an ajax call on an onchange event of the  
checking-of-the-box:

create the function

and then just do an action in the ExampleController

def set  
session[:checkbox] = params[:session\_setter]  
render :nothing =\> true  
end

all untested code…might need to modify the ajax statement above to  
pass the param[:session\_setter] in “parameters:…” but an idea, no?  
hth
