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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:55:17+00:00 2026-06-03T01:55:17+00:00

I have a page with an add item button. When this button is clicked,

  • 0

I have a page with an “add item” button. When this button is clicked, an ajax call is made and a table is returned with all the information from the database based on the sku entered. (Dummy data is there now for testing.) If the button is only clicked once, there is no trouble incrementing or decrementing the qty value. If the button is clicked two, or more, times, if you click the increment button on the second table it will increase the value in the first table.

I have added a counter that gives a unique number to each table created. I think what I want to do is figure out how to determine the counter number for the specific table that is being incremented and pass it to the javascript function so it works with that specific entry.

Here is the code with the button, ajax call, and javascript:

<script type="text/javascript">
    var count = 1;
    $('#items').live('pageinit',function(event){
        $('#additem').click(function () {
            //alert("add clicked");
            var request = $.ajax({
                url: "http://www.furnguy.com/app-pages/additem.php",
                type: "POST",
                data: {COUNTER : count},
                dataType: "html"
            });

            request.done(function(html) {
                //alert("here");
                if (html != '') {
                    $('#salesitems').append(html).trigger('create');
                }
            });

            request.fail(function(jqXHR, textStatus) {
                alert( "Request failed: " + textStatus );
            });
            count++;
        });
    });


    function deleteItem() {
        $('table').click(function(){
            $(this).parent().remove();
        });
    };
    function increaseQty() {
        var currentVal = parseInt($("#qty").val());
        if (currentVal != NaN) {
            $("#qty").val(currentVal + 1);
        }
    };
    function decreaseQty() {
        var currentVal = parseInt($("#qty").val());
        if (currentVal != NaN) {
            $("#qty").val(currentVal - 1);
        }
    };



</script>
</head>
<body>
<div data-role="page" id="items" data-title="Sales Entry - Items">
    <div data-role="header">
        <h1>Sales Entry</h1>
    </div><!-- /header -->
    <div data-role="content">
        <div id="main_nav">
            <span style="float: left; display: inline; width: 100px;">
                <label>Enter SKU</label>
            </span>
            <span style="float: left; display: inline; width: 250px;">
                <input type="text" name="initialsku" id ="initialsku" />
            </span>
            <br /><br /><br />
            <button id="additem" data-icon="plus" data-inline="true" data-mini="true" data-theme="b">Add Item</button>

            <!-- <button id="removeitem" data-icon="minus" data-inline="true" data-mini="true" data-theme="b">Remove Item</button> -->
            <div id="salesitems"></div>
        </div>
    </div><!-- /content -->
</body>
</html>

here is the page being called by the ajax:

<?php
$counter = $_POST['COUNTER'];
?>
<body>

<div data-role="fieldcontain"> 
<div class="addItems"> 
    <table id="myTable" style="border-bottom: 1px solid black;"> 
        <tr> 
            <td style="width: 50px;"> 
                <label for="qty">Qty:</label> 
            </td> 
            <td style="width: 75px;"> 
                <input type="button" value="+" id="increase" onclick="increaseQty();" style="float: left; display: inline;" />
                <input type="button" value="-" id="decrease" onclick="decreaseQty();" style="float: left; display: inline;" />
                <input type="text" name="qty" id="qty" value="1" style="float: left; display: inline;" />
            </td> 
            <td style="width: 50px;"> 
                <label for="sku">SKU:</label> 
            </td> 
            <td style="width: 350px;"> 
                <input type="text" name="sku" id="sku" readonly="readonly" value="123526874256" /> 
            </td> 
            <td style="width: 50px;"> 
                <label for="retail">Retail:</label> 
            </td> 
            <td style="width: 250px;"> 
                <input type="text" name="retail" id="retail" readonly="readonly" value="$1599.99"  /> 
            </td>
            <td id="tableNumber">
                <?php echo $counter; ?>
            </td> 
        </tr> 
        <tr> 
            <td style="width: 50px;"> 
                <label for="desc">Desc:</label> 
            </td> 
            <td colspan="5"> 
                <input type="text" name="desc" id="desc" readonly="readonly" value="This is a really big couch." /> 
            </td> 
            <td> 
                <input type="button" value="X" onclick="deleteItem();" />
            </td> 
        </tr> 
    </table> 
</div> 
</div>

Anyone have suggestions about this? I would really appreciate the help as I have been working on this for a couple days now.

Thanks in advance!

  • 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-03T01:55:18+00:00Added an answer on June 3, 2026 at 1:55 am

    Every time you click the button, you are inserting a new table with a #qty input. When you later try to increase quantity, jQuery just finds the first #qty in the dom: your first table.

    You should probably set a unique id on your qty input, e.g.:

    <input type="button" value="+" id="increase" onclick="increaseQty('qty_<?php echo $_POST['INITIALSKU']; ?>');" style="float: left; display: inline;" />
    <input type="button" value="-" id="decrease" onclick="decreaseQty('qty_<?php echo $_POST['INITIALSKU']; ?>');" style="float: left; display: inline;" />
    <input type="text" name="qty" id="qty_<?php echo $_POST['INITIALSKU']; ?>" value="1" style="float: left; display: inline;" />
    

    and then rewrite the increase/decrease functions to take the id of the field to modify. I don’t actually speak PHP but you get the idea

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

Sidebar

Related Questions

I have multiple forms on a page where each form will add individual item
I have a page like this: <form class=ajax method=post action=add_item.php> [text input] [submit button]
I have next situation: I should allow to see Add Rendering button in Page
I have a page where user dynamically add search condition(s) to filter out records.
I have a page where the user can dynamically add file upload boxes. Adding
I have a search page and want to add some filters to it, my
I have a PHP page, in Wordpress. When I add a inline Thickbox to
I have some ASP.NET page and webservice WebMethod() methods that I'd like to add
I have a problem: I've add a Jquery UI drag-n-drop widget to my page,
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);

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.