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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:59:10+00:00 2026-05-13T09:59:10+00:00

There is a one section of orders page where users can add new fields

  • 0

There is a one section of orders page where users can add new fields to add new products. They choose a product from a drop down menu and its price is written in another column. I need to add a functionality that will allow users to enter quantity amount, and total price will be updated as soon as quantity amount changes. I tried it with the following codes but I keep receiving 0 for the total price.

My codes.

$('#AddProduct').click(function() {
    var i = 0;
    var adding = $(+(i++)+'<div class="row'+(i)+'"><div class="column width50"><input type="text" id="PRODUCTNAME" name="PRODUCTNAME'+(i)+'" value="" class="width98" /><input type="hidden" class="PRODUCTID" name="PRODUCTID" /><input type="hidden" class="UNITPRICE" name="UNITPRICE'+(i)+'" /><small>Search Products</small></div><div class="column width20"><input type="text" class="UNITQUANTITY" name="UNITQUANTITY'+(i)+'" value="" class="width98" /><small>Quantity</small></div><div class="column width30"><span class="prices">Unit Price:<span class="UNITPRICE"></span><br />Total Price:<span class="TOTALPRICE"></span><br /><a href="#" id="RemoveProduct(".row'+(i)+'");">Remove</a></span></div>');    
    $('#OrderProducts').append(adding);

    adding.find("#PRODUCTNAME").autocomplete("orders.cs.asp?Process=ListProducts", {
        selectFirst: false
    }).result(function(event, data, formatted) {
        if (data) {
            adding.find(".UNITPRICE").html(data[1]);
            adding.find(".PRODUCTID").val(data[2]);
            adding.find(".TOTALPRICE").html(data[1] * $('.UNITQUANTITY').val()); 
        }
    });

    return false;
});


            <div id="OrderProducts">
                <a href="#" id="AddProduct"><img src="icons/add.png" alt="Add" /></a>
            </div>  
  • 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-05-13T09:59:10+00:00Added an answer on May 13, 2026 at 9:59 am

    You function seems to act on the result of the auto complete so since the .UNITQUANTITY may not have been set it will not get anything other then 0 unless you put a value in for the UNITQUANTITY before you select from the auto complete. But you would need to leave that function as it but possibly add a default of 1 to the UNITQUANTITY then add another function handling the event that the UNITQUANTITY value has changed then do the last line of that inline function and you should have the results you want.

    I would suggest adding the following right before your return false;

    adding.find(".UNITQUANTITY").change(function()
      {
        adding.find(".TOTALPRICE").html(adding.find(".UNITPRICE").val() * adding.find(".UNITQUANTITY").val()); 
      });
    

    Also edit your inline function to do the following…

    adding.find(".UNITPRICE").html(data[1]);
    adding.find(".UNITPRICE").val(data[1]);
    adding.find(".PRODUCTID").val(data[2]);
    adding.find(".TOTALPRICE").html(data[1] * $('.UNITQUANTITY').val()); 
        
    

    Your first line was setting the html of the unit price but not the val so when we tried to retrieve with the .val() it returned 0

    Also as a note you should consider adding some round to 2 decimal places to make sure you don’t end up with too many decimals for a total price.

    Unit Price:50.99

    Total Price:2804.4500000000003

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

Sidebar

Related Questions

There is a one section of orders page where users can add new fields
One of our bigger sites has a section where users can send questions to
There is one form, inside the form there are many checkboxes. Two operations can
there is one think, i can't understand anyway:((( when i try to set cookie(it
Can you give chapter and verse from one of the three C standards (preferably
Is there one method or property in the .NET Framework that tells if an
I'm looking for a standard dual-map structure - is there one implemented in std/boost/another
Network file systems are offered by Windows and (L)Unix. Is there one for IBM
There is one table. Parent_id references same table id. How insert raw if parent_id
There is one client who cannot see the img title tags in IE8. Is

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.