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 8601865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:56:37+00:00 2026-06-12T01:56:37+00:00

I am writing a small invoice application in Yii . I have the database

  • 0

I am writing a small invoice application in Yii. I have the database for the model item. The item database is something like this

  +++++++++++++++++
  |  InvoiceItems |
  +++++++++++++++++
  +      id       +
  +      name     +
  +  description  +
  +    unit_cost  +
  +    quantity   +
  +    tax        +
  +    total      +
  +++++++++++++++++

Now, in item model I have made a dropdown list where I am fetching all the item name with its unit_cost, quantity, tax etc in Ajax. In order to do the total, I have the business logic as:

  1. unit_cost will be multiplied by quantity
  2. Tax will then be added to the total.
  3. The total should finally pop up in the total field in the _form.php file.

For the calculation, I have written this jQuery script:

<script type="text/javascript">
jQuery(document).ready(function(){
  jQuery("#InvoiceItems_unit_cost, #InvoiceItems_quantity, #InvoiceItems_tax").on('keyup',function(event){
    var subtotal = jQuery("#InvoiceItems_quantity").val() * jQuery("#InvoiceItems_unit_cost").val();
    var total = subtotal + (subtotal  * jQuery("#InvoiceItems_tax").val() / 100);
    jQuery("#InvoiceItems_total").val(total);
  });
});
</script>

This is working fine when I am manually inserting the values but it’s not working when the values are coming from the database. I am totally stuck.

UPDATE

When I am trying to see the value after fetching from the database through ajax in console tab of firefox just like console.log("#InvoiceItems_quantity").val(), it is showing an empty string.
Ajax code to fetch data from the database in form of json

        <?php echo $form->dropDownList($customers,'customer_name',CMap::mergeArray(CHtml::listData(Customers::model()->findAll(), 'customer_name',       'customer_name'
        ),
        array(
        'empty'=>array('Select'=>'- - Choose One - -'),
        'id'=>'Customers_name',
        'ajax'=> array(
            'type'=>'GET',
            'id'=>'abc',
            'url'=>$this->createUrl('Invoices/customerdetails'),// action that will generate the data
            'data'=>'js:"customer_name="+$(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:updateFieldsCustomers',// a javascript function that will execute when the request completes
            'beforeSend'=>'js:function(){
                if($("#Customers_name").val() == "create_customer_link") {
                    addCustomers();
                    $("#dialogCustomers").dialog("open");
                    return false;
                }
            }',
        ),
        'options'=>array(
            'create_customer_link' => array('class'=>'create-link'),
        )
    )
);?>

   <?php
  Yii::app()->clientScript->registerScript('update','
  function updateFieldsCustomers(data, textStatus, jqXHR){
  // select each input field by id, and update its value
  $("#InvoiceItems_unit_cost").val(data.unit_cost);
  $("#InvoiceItems_quantity").val(data.quantity);
  $("#InvoiceItems_discount").val(data.discount);
  // similarly update the fields for the other inputs
  }
');
  ?>

Recent Update

When I tried for console.log("#InvoiceItems_quantity").val() I saw that it is showing the actual value of that field after change. Means when one value is selected it is showing the value of previous entered value in console panel. I think all this is working as I have used on change function but when I am using .select its not working at all.Not any value is showing in console panel.

  • 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-12T01:56:38+00:00Added an answer on June 12, 2026 at 1:56 am

    I got the solution for this question. It should be like this

    <script type="text/javascript">
    jQuery(document).ready(function(){
      jQuery("#Product_name").ajaxComplete(function(event,request,settings){
        var subtotal = jQuery("#InvoiceItems_quantity").val() * jQuery("#InvoiceItems_unit_cost").val();
        var total = subtotal + (subtotal  * jQuery("#InvoiceItems_tax").val() / 100);
        jQuery("#InvoiceItems_total").val(total);
      });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Yii I am writing a small application called Invoice Application. In that I
I have an application where I am reading and writing small blocks of data
I am new to network programming, and have been learning this by writing small
While writing a small paint-like application (for myself), I originally had the following code
I'm currenty writing small application for image processing. However I have a big problem
I'm writing a small Windows application in Visual C++ without MVC. Its really small,
I am writing a small e-shop application with Symfony 2 and I need some
I'm writing a small RMI based Chat application. The idea is: the Client registers
I'm currently writing a small script using pygame, but I don't believe this question
While writing a small C# application for myself I realized that it would be

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.