RE: on change of drop down showing a new textfield

Daniel,
thanks for your reply ,
but i have started RoR a week back and i am really new, what
you said i
didn’t get,
well i will google around what you have said and try to find
out the way

Observe_field allows u to observe a text box and execute code on the
server using ajax.

Take a look at the tutorial here

Basically the code on the server can return anything back to you. It
could be a list of things that you can display in an existing control or
it could be javascript code that u could execute to show a new control.

Hope that helps.

Bharat

On 6/19/06, Bharat A. [email protected] wrote:

Message-ID:
[email protected]
Content-Type: text/plain; charset=“iso-8859-1”

Daniel,
thanks for your reply ,
but i have started RoR a week back and i am really new, what
you said i
didn’t get,
well i will google around what you have said and try to find
out the way

Sorry I didn’t make myself a little clearer. Sometimes I get a little
carried away :wink:

A good overview of how to use observe_field is on the wiki at
http://wiki.rubyonrails.com/rails/pages/How+to+make+a+real-time+search+box+with+the+Ajax+helpers

Your original requirements would probably be better served by using a
text_field_with_auto_complete. In your controller use

auto_complete_for :object, :method

Make sure that you have included <%= javascript_include_tag :defaults %>
in
your application controller or nothing will happen.

And then in your view <%= text_field_with_auto_complete “customer”,
“name”
%>

This will give you a drop down box generated by javascirpt, that the
user
can select. It will update a drop down list while the user is in the
text
field, and will provide values based on what they type in. If they don’t
want to select from the list, they can type in a new value.

Then in your controller you use, (Assuming that the field is for a
Customer
name

@customer = Customer.find_or_create_by_name( params[:customer][:name])

Hopefully this will be enough to get you started. There is good info on
the
rails wiki, on various blogs, and of course google.

Cheers

Observe_field allows u to observe a text box and execute code on the