Populate data in another fields on selection

Hi,
I would like to know how to populate data in another text fields on
selection from a drop down

For Ex

  1. The form contains 4 fields out of which 3 are text fields and the 4th
    one is
    drop down list.
  2. i would like to know how to populate the 3 text fields with data
    simultaneously
    on selection from the drop down list.

Please Help.

Koli K. wrote:

Hi,
I would like to know how to populate data in another text fields on
selection from a drop down

For Ex

  1. The form contains 4 fields out of which 3 are text fields and the 4th
    one is
    drop down list.
  2. i would like to know how to populate the 3 text fields with data
    simultaneously
    on selection from the drop down list.

Please Help.

Try using observe_field!

In yr view file add this

In View:

<%= observe_field ‘field_id’,
:url => url_for({:controller=>
‘yr_controller_name’,:action=>‘some_method_in_controller’}),
:method => :post,
:with => ‘field_id’ %>

In Controller

def some_method_in_controller
#…
some code to find the objects to be populated in the text fields.
…#

page.replace_html ‘div_id1’, text_field_tag(‘text_field_id_1’,@object)
page.replace_html ‘div_id2’, text_field_tag(‘text_field_id_2’,@object)
page.replace_html ‘div_id3’, text_field_tag(‘text_field_id_3’,@object)

end

def some_method_in_controller
#…
some code to find the objects to be populated in the text fields.
…#

page.replace_html ‘div_id1’, text_field_tag(‘text_field_id_1’,@object)
page.replace_html ‘div_id2’, text_field_tag(‘text_field_id_2’,@object)
page.replace_html ‘div_id3’, text_field_tag(‘text_field_id_3’,@object)

end

This didn’t work though can u be more descriptive??

Ratnavel S. wrote:

wat does it show in development log…?

can u paste the error log…

i have 2 tables entries and problems which is associated with each
other.

The drop down list is poulated with one of the fields of the problems
table:
i’m able to that corresponding id into the entries table.

i have 3 other text fields which shoould be populated with the
information
of the id that i have selected from the drop down
This is the part that i’m not able to do.

MY view:
<%= error_messages_for ‘entry’ %>
<% @cats = Problem.find_all %>

Nature of the problem

<% @cats.each do |cat| %> > <%= cat.natureofproblem %> <%end%> TEXT FIELD1 TEXT FIELD2

How to populate these text field with the id info that i have from
select dropdown.

wat does it show in development log…?

can u paste the error log…

Koli K. wrote:

Ratnavel S. wrote:

wat does it show in development log…?

can u paste the error log…
cat| %>
<option value=<%=cat.id%> > <%=
cat.natureofproblem %>
<%end%>

TEXT FIELD1 TEXT FIELD2

How to populate these text field with the id info that i have from
select dropdown.

where do i do the page.replace_html>

can u show me a example>>

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