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

  • Home
  • SEARCH
  • 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 548895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:07:41+00:00 2026-05-13T11:07:41+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. The problem here is, every time user adds new fields, new fields should have names as PRODUCTNAME1, PRODUCTNAME2, PRODUCTNAME3, and so on. Right now, every new field added has 1 value. Its stuck there. I hope I made some sense.

$('#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)+'" value="" /><input type="hidden" class="TOTALPRICE" name="TOTALPRICE'+(i)+'" value="" /><small>Search Products</small></div><div class="column width20"><input type="text" class="UNITQUANTITY" name="UNITQUANTITY'+(i)+'" value="1" 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").val(data[1]);
            adding.find(".UNITPRICE").html(data[1]);
            adding.find(".PRODUCTID").val(data[2]);
            adding.find(".TOTALPRICE").val(data[1] * $('.UNITQUANTITY').val()); 
            adding.find(".TOTALPRICE").html(data[1] * $('.UNITQUANTITY').val()); 
        }
    });

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


    return false;
});
  • 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-13T11:07:41+00:00Added an answer on May 13, 2026 at 11:07 am

    i is reset to 0 every time $('#AddProduct').click() is called; I don’t think that’s what you want. You would need i to be declared outside of the function that’s passed into $('#AddProduct').click(). One way to do this would be through a closure.

    (Note: I haven’t tested this.)

    var onClick = (function() {
        var i = 0;
        return (function () {
            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)+'" value="" /><input type="hidden" class="TOTALPRICE" name="TOTALPRICE'+(i)+'" value="" /><small>Search Products</small></div><div class="column width20"><input type="text" class="UNITQUANTITY" name="UNITQUANTITY'+(i)+'" value="1" 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").val(data[1]);
                    adding.find(".UNITPRICE").html(data[1]);
                    adding.find(".PRODUCTID").val(data[2]);
                    adding.find(".TOTALPRICE").val(data[1] * $('.UNITQUANTITY').val()); 
                    adding.find(".TOTALPRICE").html(data[1] * $('.UNITQUANTITY').val()); 
                }
            });
    
            adding.find(".UNITQUANTITY").change(function()
            {
                adding.find(".TOTALPRICE").val(adding.find(".UNITPRICE").val() * adding.find(".UNITQUANTITY").val()); 
                adding.find(".TOTALPRICE").html(adding.find(".UNITPRICE").val() * adding.find(".UNITQUANTITY").val()); 
            });
    
            return false;
        });
    })();
    
    $('#AddProduct').click(onClick);
    
    • 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
I'm trying to create a Comments section in my wiki. There's one solution on
What is the difference between these three heavily related fields? Is there one specific
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
$0 is the variable for the top level Ruby program, but is there one
What are the best algorithms for sorting data in C#? Is there one sorting
Network file systems are offered by Windows and (L)Unix. Is there one for IBM
There's one thing I haven't found in RFC 2616 ("Hypertext Transfer Protocol -- HTTP/1.1")

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.