Checking form values inside RJS

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.

On Dec 11, 2007 9:50 AM, Ian [email protected] 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.

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

Now it’s looking good. Appreciate it!

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’)”)

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.