koli
December 27, 2007, 9:21am
1
Hi,
I would like to know how to populate data in another text fields on
selection from a drop down
For Ex
The form contains 4 fields out of which 3 are text fields and the 4th
one is
drop down list.
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
December 27, 2007, 10:02am
3
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
koli
December 28, 2007, 6:21am
4
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??
koli
December 28, 2007, 8:53am
5
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.
koli
December 28, 2007, 6:31am
6
wat does it show in development log…?
can u paste the error log…