F.select onchange determine other fields in view

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

<%= f.label :type_id%>
<%= f.select :type_id,Type.all.collect{|c| [c.description,c.id]}, :onchange=>"HERE I NEED TO DO SOMETHING WHAT?" %>

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:

<%= f.label :value %> <%= f.select :value,Test.get_tests.all.collect{|c| [c.description,c.test_id]} %>

If its not 5
I want

<%= f.label :value %>
<%= 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

bill walton wrote:

Hi Tz Le,
On Tue, 2009-08-25 at 21:48 +0200, Tz Le wrote:

Now when they change and the id is now 5
If its not 5
I want

<%= f.label :value %>
<%= 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.

Tz Le wrote:

bill walton wrote:

Hi Tz Le,
On Tue, 2009-08-25 at 21:48 +0200, Tz Le wrote:

Now when they change and the id is now 5
If its not 5
I want

<%= f.label :value %>
<%= 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?

Hi Tz Le,
On Tue, 2009-08-25 at 21:48 +0200, Tz Le wrote:

Now when they change and the id is now 5
If its not 5
I want

<%= f.label :value %>
<%= 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

Lee S. wrote:

Is this what you’re trying to do?

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

Thank you, Its similar. But all these posts are telling me based on one
select to populate a second select.
What if based on one select, I want to determine the other field- if its
select or if its a text field.
I am very new to Ruby on Rails and I am not sure how to go about this.

Thank you

Is this what you’re trying to do?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs