Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8184031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:21:42+00:00 2026-06-07T01:21:42+00:00

I am doing a small application in Yii Framework for that my database is

  • 0

I am doing a small application in Yii Framework for that my database is something like this

 === Invoices ===
  id (PK)
  customer_id
  invoice_title
  order_no
  invoice_issue_date
  due_date
  description

  === Customers ===
  id (PK)
  email_address
  customer_name
  address
  city
  state
  postal_code
  description

I have rendered the Customer model in Invoice model so that I can enter all the values for both models in a single Invoice form.But there is one problem,let us assume that I have a customer name xyz which I had saved before.Now when I am going to again fill the Customer name with xyz,it should show all the fields of both models like invoice_title,order_no,invoice_issue_date,due_date,description,email_address,customer_name,address etc. in that input fields of the form so that I don’t have to re-enter all the fields again.So how this can be achive in Yii framework.Any help and suggestions will be highly appreciable.More clarification on codes that I have done can be shared if needed.
Please help me out.I am totally stuck here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:21:43+00:00Added an answer on June 7, 2026 at 1:21 am

    To do this as everyone has already mentioned you need ajax, and some javascript. The logic is something like this:

    1. When a value is selected in the dropdown for customer name, trigger an ajax call to retrieve the information about that user. This can be easily done with the ajax option, which is available as an additional htmlOption for some html element helpers in CHtml, as part of clientChange.

      echo $form->dropDownList($model,'customer_name',CHtml::listData(Customers::model()->findAll(),'id','customer_name'),
         array(// htmlOptions
           'ajax'=>array(// special htmlOption through clientChange, for ajax
                 'type'=>'GET', 
                 'url'=>$this->createUrl('controllername/customerdetails'),// action that will generate the data
                 'data'=>'js:"id="+$(this).val()',// this is the data that we are sending to the action in the controller
                 'dataType'=>'json',// type of data we expect back from the server
                 'success'=>'js:updateFields'// a javascript function that will execute when the request completes successfully
           )
         )
       );
      

      The documentation for the above options for ajax can be seen in jquery’s ajax documentation.

    2. Then in the server side find the particular customer, and send a response to the browser. Example:

      // in the controllername code an action that will return the values as json
      public function actionCustomerdetails($id){
          $var=Customers::model()->findByPk($id);
          echo CJSON::encode($var);
      }
      
    3. When you receive the server response populate the respective fields. This can be done in the success function callback for ajax, in the above code it was updateFields:

      Yii::app()->clientScript->registerScript('update','
          function updateFields(data, textStatus, jqXHR){
              // select each input field by id, and update its value
              $("#Customers_postal_code").val(data.postal_code);
              $("#Customers_city").val(data.city);
              $("#Customers_address").val(data.address);
              // similarly update the fields for the other inputs
          }
      ');
      

    Notes:
    Your customer can have many invoices, so the question will be which invoice to select given a customer name. That’s something you’ll have to handle, i think my answer has enough code to get you going.

    To know the input field ids, you can simply check the generated html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi im doing a small application in the Zend Framework 1.8 Web Application Development
I am just doing a small application with 3 tables. Applicants Positions ApplicantsPerPosition. This
I'm working with this small web application (1 page) built by someone else that
i am doing one small application , wheich have login functionality, in the user
While doing some small regex task I came upon this problem. I have a
I'm doing jquery small animation of fade in to form validation This is working
I am doing this small exercise. declare @No decimal(38,5); set @No=12345678910111213.14151; select @No*1000/1000,@No/1000*1000,@No; Results
I am doing a small android application, which will show established WiFi connection is
I'm doing a very small windows application consisting of just a single executable. As
I am implementing a small application (observer) that needs to attach itself to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.