Updating fields based on another field value using ajax


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.


Hi Dan,

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

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

here is the documentation on the callbacks:


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

hope that gets you somewhere.


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