updating fields based on another field value using ajax

Hello,

I have a form where the user can enter an address. Based on the user entering the zip code, I would like to use ajax to pull the city, state and county from the application database. observe_field doesn't look quite right as it updates a dom element, not the fields themselves.

I would appreciate any advice on rolling this functinality myself.

Thanks, Dan

Hi Dan,

I think you can try to use the callback functionality to do this.

http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000422 the observe_field doc says you can use any of the options from link_to_remote so if you can use the callbacks then you can have those perform javascript actions to set the field.value for the other form fields.

here is the documentation on the callbacks:

http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000412

the ajax call you make can return those values to you in a JSON string or something, i guess.

hope that gets you somewhere.

-Tim

Dan Munk wrote: