f.select onchange determine other fields in view

I am trying to create a view/form that has a dropdown

<p>
    <%= f.label :type_id%><br />
    <%= f.select :type_id,Type.all.collect{|c| [c.description,c.id]},
:onchange=>"HERE I NEED TO DO SOMETHING WHAT?" %>
    <!-- on change or on select show drop down for value otherwise
regular value -->
  </p>

Now when they change and the id is now 5
HERE I NEED TO CHECK THE VALUE SELECTED BY THE FIRST SELECT
1. How do I access the id of the first select and what was selected?

I want to create:
<p>
   <%= f.label :value %>
    <%= f.select :value,Test.get_tests.all.collect{|c|
[c.description,c.test_id]} %>
  </p>

If its not 5
I want
<p>
    <%= f.label :value %><br />
    <%= f.text_field :value %>

Please if you can tell me how to access the first select- do I set an
id? and what I do onchange since its in the same form a few lines down I
want to have a different field.

Thank you

Hi Tz Le,

Tz Le wrote:

bill walton wrote:

Hi Tz Le,

Now when they change and the id is now 5
If its not 5
I want
<p>
    <%= f.label :value %><br />
    <%= f.text_field :value %>

Please if you can tell me how to access the first select- do I set an
id? and what I do onchange since its in the same form a few lines down I
want to have a different field.

You need to put an observe_field on the first field that makes an ajax
call to render a partial containing the second field with the
appropriate choices based on the first selection. Try a google search
on 'rails observe_field select'.

HTH,

Bill

Ok.Thank you, I will search for this.

I read about the observe field select.
Two things: Every post I see determines a second select based on the
first select. What I am trying to do is based on the first select either
display a second select or display a text field(this will depend on the
first select value)

I tried to use the observe field and I am not sure of two things:
the action=> 'funtion'
Do I need to create in the controller any function and if yes what?
basically if there is a change in the select,
I want to check the value if it equals 5,
display a second select,
if not display text field.

Also what does the parameter :with do?
The :update=> "myfield name" this field should be the second select name
and then how to I display the text field instead?

Is this what you're trying to do?

http://railscasts.com/episodes/88-dynamic-select-menus