# Checking form values inside RJS

**URL:** <https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739>\
**Category:** Rails\
**Created:** [December 11, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739 "2007-12-11T16:02:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 11, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739/1 "2007-12-11T16:02:09Z")

</div>

I’m testing a small bit of functionality using RJS. I have a form with  
a radio-button set – a Yes button and No button – and a text input.

I’m using observe\_form to send the entire form to the server, instead  
of observe\_field.

What I’d like to happen is to have the text input hidden if I click  
Yes and the text input displayed if I click No.

In order to decide what action to perform – show or hide – I need to  
know the value of the radio button. I imagine that my rjs template  
would look something like this

if value\_of\_radio == “Yes”  
page[“textinput”].hide  
else  
page[“textinput”].Show  
end

I just don’t know how to get that value\_of\_radio populated.

Any suggestions or pointers will be much appreciated. It could be that  
I’m missing something simple, or maybe I’m going about this all wrong.

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 11, 2007, 5:17pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739/2 "2007-12-11T17:17:52Z")

</div>

On Dec 11, 2007 9:50 AM, Ian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In order to decide what action to perform – show or hide – I need to  
> know the value of the radio button. I imagine that my rjs template  
> would look something like this
> 
> if value\_of\_radio == “Yes”  
> page[“textinput”].hide  
> else  
> page[“textinput”].Show  
> end

The input values will be in params[], just like with any other request.

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 11, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739/3 "2007-12-11T19:32:22Z")

</div>

Thanks for this reply. I couldn’t get the params thing to work until I  
read this thread:

[http://www.ruby-forum.com/topic/81608](http://www.ruby-forum.com/topic/81608)

Now it’s looking good. Appreciate it!

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 11, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739/4 "2007-12-11T22:43:14Z")

</div>

Looking at the API you can keep the observe\_form tag and pass it a  
straight JS function.

observe\_field(“glass”, :frequency =\> 1, :function =\> “alert(‘Element  
changed’)”)

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [December 11, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/checking-form-values-inside-rjs/122739/5 "2007-12-11T22:16:47Z")

</div>

Are you sending the request to the server simply so you can hide or  
unhide a field? If so you should just use js and an onclick event.
