Ajax method to populate form data

I am looking for the best way to accomplish something that seems simple and a common occurence, but cannot seem to find any great examples.

On a form within my Yii application, I would like to have a button that triggers some ajax call to my controller. This part is easy and well documented.

Within that action, I would like to fill out some fields that are in the form.


  1. Button next to zip code that when clicked looks up and populates city and state fields in the form.

  2. Button to copy 1 address to another. (easier as it can be 100% client js)

Optins I see are:

  1. Form fields to be modified are in a div linked to the ajax to render partial.

  2. Controller action renders new js function that pushes the data into the form fields.

Are there other ways to accomplish this?

Is there a recommended way? Why?