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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:52:53+00:00 2026-06-16T03:52:53+00:00

I have a jquery problem, I am fetching results in an array from my

  • 0

I have a jquery problem, I am fetching results in an array from my sql database.
The items are in a table tr td. Each row holds a unique id.

but when i do the sum or doing onkeyup for one text box the all total change also.

I am uding an onKeyUp event for Qty.

eg.:

Qty = 3

Bedrag = 20

Totaal (expected) = 60

Here is a screenshot:
enter image description here

Is my jQuery code wrong?

jQuery(document).ready(function(){

    var j = 0;
    /* COMPUTATION new item */
    jQuery('input[id=new_quan_'+j+']').keyup(function(){
        j++;
        var new_sum = parseInt($('input[id=new_quan_'+j+']').val(), 10);
        new_sum *= parseInt($('input[id=new_amt_'+j+']').val(), 10);
        jQuery('input[id=new_total_'+j+']').val(new_sum);
    });
}); 

Here is the HTML and PHP code:

<table cellpadding="5" cellspacing="0" width="100%" id="computation_table">
    <tbody>
    <tr>
        <th>Categories</th>
        <th>Qty</th>
        <th>Omschrijving</th>
        <th>Bedrag</th>
        <th>Totaal</th>
        <th>BTW</th>
        <th></th>
    </tr>
    <?
    $quo_com = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
    $get_btw = mysql_fetch_array( $quo_com );
    if ( $get_btw['currency'] == 'euro' ) {
        $msg_tot = '&euro;';
    } elseif ( $get_btw['currency'] == 'usd' ) {
        $msg_tot = '&#36;';
    }

    $sqlview = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE user_code = '".$_GET['uc']."' and footnote = 'new' and active='1' " ) or die ( mysql_error() );
    $j = 0;
    while( $row = mysql_fetch_array( $sqlview ) ) {
    ?>
    <tr>
        <td>
            <input type="hidden" name="id_<?=$j?>" value="<?=$row['q_id'];?>" />
            <input type="hidden" name="counter" value="<?=$j?>" />
            <input type="text" name="category_<?=$j?>" class="text_com" value="<?=$row['category'];?>" />
        </td>
        <td>
            <input type="text" name="quantity_<?=$j?>" id="new_quan_<?=$j?>" class="text_com" value="<?=$row['quo_quantity'];?>" /> x
        </td>
        <td width="200">
            <input type="text" name="quo_definition_<?=$j?>" class="input" value="<?=$row['quo_definition'];?>" />
        </td>
        <td>
            <input type="text" name="quo_amt_<?=$j?>" id="new_amt_<?=$j?>" class="text_com" value="<?=$row['quo_amt'];?>" />
        </td>
        <td id="total">
            <input type="text" name="quo_total_<?=$j?>" id="new_total_<?=$j?>" class="text_com" value="<?=$row['quo_total'];?>" />
        </td>
        <td>
            <input type="text" name="quo_btw_<?=$j?>" class="text_com" value="<?=$row['quo_btw'];?>" />
        </td>
    </tr>
<?
    $j++;
    }
?>
    </tbody>
</table>
</div>
<br />
<!-- END OF COMPUTATION UPDATE -->
<input type="submit" name="up_item_list" value="Werk de vorm" /> - <input type="submit" name="new_save_list" value="Opslaan nieuw item" /> - <a href="">Annuleren</a>
</form>
  • 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-16T03:52:54+00:00Added an answer on June 16, 2026 at 3:52 am

    It is better to use classes to find corresponding elements instead of that id built with j (even have no idea how it should work looking at your code)

    jQuery('.new_quan').keyup(function(){        
            var new_sum = parseInt(jQuery(this).val(), 10);
            new_sum *= parseInt(jQuery(this).closest('tr').find('.new_amt').val(), 10);
            jQuery(this).closest('tr').find('.new_total').val(new_sum);
        });
    

    And update php code:

        while( $row = mysql_fetch_array( $sqlview ) ) {
        ?>
        <tr>
            <td>
                <input type="hidden" name="id_<?=$j?>" value="<?=$row['q_id'];?>" />
                <input type="hidden" name="counter" value="<?=$j?>" />
                <input type="text" name="category_<?=$j?>" class="text_com" value="<?=$row['category'];?>" />
            </td>
            <td>
                <input type="text" name="quantity_<?=$j?>" id="new_quan_<?=$j?>" class="text_com new_quan" value="<?=$row['quo_quantity'];?>" /> x
            </td>
            <td width="200">
                <input type="text" name="quo_definition_<?=$j?>" class="input" value="<?=$row['quo_definition'];?>" />
            </td>
            <td>
                <input type="text" name="quo_amt_<?=$j?>" id="new_amt_<?=$j?>" class="text_com new_amt" value="<?=$row['quo_amt'];?>" />
            </td>
            <td id="total">
                <input type="text" name="quo_total_<?=$j?>" id="new_total_<?=$j?>" class="text_com new_total" value="<?=$row['quo_total'];?>" />
            </td>
            <td>
                <input type="text" name="quo_btw_<?=$j?>" class="text_com" value="<?=$row['quo_btw'];?>" />
            </td>
        </tr>
    <?
        $j++;
        }
    

    Here I have added few classes to your inputs so than it is possible to find those elements in even handler with find .find('.new_total') and .find('.new_amt')

    .closest("tr") will find a tr which contains all inputs you need to update total. and find('...') will search inside that tr only, updating only related input values only that way.

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

Sidebar

Related Questions

I have jquery code to delete data row by row in my table view.
just having a little issue figuring this jquery problem out. I have a table
I have JQuery dialog box for inserting new row in table. And everything works
hey everyone, here is the site SEE BELOW I have a slight jquery problem
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have a JQuery (using JQuery 1.4.2) problem that exhibits only in IE8 in
i'm new to jquery .I have problem in the following code .I saved it
I have a problem with slashes! I have some jQuery for handling generic dialogs
I have a problem with jQuery parallax effect for my body's background. Here is
I have a problem with jQuery, I want to change a DIV (not 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.