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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:08:13+00:00 2026-06-15T13:08:13+00:00

i was wondering if my jquery is correct for add the td and get

  • 0

i was wondering if my jquery is correct for add the td and get the total for the sub total and total.

my jquery is,

$(document).ready(function(){
    var sum = 0;
    var td = $('input[name=sumof]').val();
    jQuery.each(td,function(number){
            sum += parseInt($(this).val());
        $('#total_f').val(sum);
    });
})

and this is my html

<div class="quotation_computation" style="margin-top:50px;">
    <table cellpadding="5" cellspacing="0" width="100%">
        <tr>
            <th>#</th>
            <th>Definition</th>
            <th>Amount</th>
            <th>Total</th>
            <th>BTW</th>
        </tr>
        <?
        $get_details = mysql_query( "SELECT * FROM jon_com_quo_computation WHERE com_code = '".$_GET['ccom']."' " ) or die ( mysql_error());

            $found_record = mysql_num_rows( $get_details );
            if ( $found_record != 0 ) {
            while( $set_det = mysql_fetch_array( $get_details ) ) {
                $total = $set_det['quo_quantity'] * $set_det['quo_amt'];
            ?>
        <tr>
            <td class="add_text">
                    <?=$set_det['quo_quantity'];?> x
            </td>
            <td class="add_text" width="250"><?=$set_det['quo_definition'];?></td>
            <td class="sum_text">
                    <?=$set_det['quo_amt'];?>
                <input type="hidden" name="sumof" value="<?=$set_det['quo_amt'];?>" />
            </td>
            <td class="add_text" id="total"><?=$total;?></td>
            <td class="add_text"><?=$set_det['quo_btw'];?></td>
        </tr>
        <?
                }
            } else {
            ?>                
        <tr>
            <td class="add_text">#</td>
            <td class="add_text">Definition</td>
            <td class="add_text">Amount</td>
            <td class="add_text" id="total">Total</td>
            <td class="add_text">BTW</td>
        </tr>
        <?
            }
            ?>
    </table>
</div>

<div class="sub_total_computation" style="width:200px; position:relative; left:325px;">
<?
    $get_total_computation = SET_SQL( "SELECT quo_btw FROM jon_com_quo_computation WHERE com_code = '".$_GET['ccom']."' " );


    ?>
    <table cellpadding="5" cellspacing="0" width="100%">
        <tr>
            <td><strong>Sub Total</strong></td>
            <td>
                <span id="total_f"></span>
                <input type="hidden" name="total_f" value="" />
            </td>
        </tr>
        <tr>
            <td><?=$get_total_computation['quo_btw'];?></td>
            <td><?=$btw;?></td>
        </tr>
        <tr>
            <td><strong>Total</strong></td>
            <td><?=$btw;?></td>
        </tr>
    </table>
</div>

if you saw the hidden name=sumof im going to put there the answer also in the td class=sum_text but the answer did not appear.
Do we need to use on .keyup function so that the jquery will appear?
Or i just need to use the PHP so that it will work?

thank you sir.

  • 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-15T13:08:14+00:00Added an answer on June 15, 2026 at 1:08 pm

    Try this:

    $(document).ready(function(){
       var sum = 0;
       $('input[name=sumof]').each(function(){
            sum += parseInt($(this).val());
       });
       $('#total_f').val(sum);
     });
    

    Your variable td would only get one value out of the input elements, and NOT be sufficient to use as an object (the input element) to loop with your each() function. Also you only need to have the function output the sum once, so I took it out of the each loop.

    To further make the function efficient You could use just the contents of the td element instead and completely remove the hidden input element:

    $(document).ready(function(){
       var sum = 0;
       $('td.sum_text').each(function(){
            sum += parseInt($(this).text());
       });
       $('#total_f').val(sum);
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already encapsulated my javascript in jQuery(document).ready(function($) { }); I was wondering what the
I am wondering if my jquery function is correct <script> window.blinker = setInterval(function(){ if(window.alerta){
I have a counter running on one of my add input jquery functions: var
I am just wondering whether that is a correct syntax in JQuery : var
Hi I was wondering if there is any jquery function around which can take
Of these two, which is correct? jQuery('someclass').click(function() { alert(I've been clicked!); }); or jQuery('someclass').each().click(function()
I'm wondering if it's normal. I add an option to a select with jQuery.
I am really wondering if jQuery remove function really remove elements from DOM. First,
i was wondering if jquery can be used to manipulate my select html element
Wondering what the best / good way of doing this would be in jQuery.

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.