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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:35:45+00:00 2026-05-27T16:35:45+00:00

What will I add if everytime user is unchecking the checkbox, the ammount will

  • 0

What will I add if everytime user is unchecking the checkbox, the ammount will be reduced ? Thanks

I have a code below :

echo '<INPUT TYPE="text" NAME="eg_payamt_[]" Value="' . $amount_dueArr[$record_count] . '" size="10"><br>';//display ammountDue (AmmountDue)                   

echo '<INPUT TYPE="text" NAME="eg_payamt_[]" Value="' . $TotalArr[$record_count] . '" size="10"><br>';//display outstanding (Total)

<td><input type="checkbox" name="pay[]" value="" /></td>

enter image description here

My question is, how to calculate the total amount inside the textbox everytime user click the checkbox ?

Thanks

can you do like this :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<table>
<tr>
<td><INPUT TYPE="text" NAME="eg_payamt_[]" Value="" size="10"><td><br>
<td><input type="checkbox" name="pay[]" value="" onclick="return calculateSum();" /></td>
</tr>
<tr>
<td><INPUT TYPE="text" NAME="eg_payamt_[]" Value="" size="10"><td><br>
<td><input type="checkbox" name="pay[]" value="" onclick="return calculateSum();" /></td>
<tr>
<td><INPUT TYPE="text" NAME="answer" id="answer" Value="" size="10"><td><br>
</tr>
</table>


<script>
    function calculateSum() {

        var sum = 0;
        //iterate through each textboxes and add the values
       //$("input:text").each(function() {
       $("input[type='text'][name='eg_payamt_[]']").each(function(){ 

            //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }

        });

        //.toFixed() method will roundoff the final sum to 2 decimal places
        $("#answer").val(sum.toFixed(2));
    }
</script>

can you do like this ? is it working ? i m trying now…

complete code :

<head>
<script type="text/javascript" src="jquery-1.7.1.js">
</script>
</head>
<script>
                                    function calculateSum() {

                                        var sum = 0;
                                        //iterate through each textboxes and add the values
                                        //$("input:textbox").each(function() {
                                        //$("input:eg_payamt_[]").each(function() { 
                                        $("input[type='text'][name='eg_payamt_[]']").each(function(){       


                                            //add only if the value is number
                                            if(!isNaN(this.value) && this.value.length!=0) {
                                                sum += parseFloat(this.value);
                                            }

                                        });
                                        //.toFixed() method will roundoff the final sum to 2 decimal places
                                        $("#answer").html(sum.toFixed(2));
                                    }
                                    </script>


     <form name="payform" method="POST" action="payment.php">
    <H2>Pay Invoices</H2>

        <table border="0"><!--begin of the table-->
            <tr>
               <td><b>Date</b></td>
               <td><b>Invoice</b></td>
               <td><b>Ammount</b></td>
               <td><b>Outstanding</b></td>
               <td><b>Pay</b></td>
            </tr>
            <tr>
                <td width="512px" colspan="5"><IMG SRC="rule-black.gif" WIDTH="800" HEIGHT="11"><br></td>
            </tr>

            <?php
                  echo '<INPUT TYPE="hidden" NAME="record" Value="'.$record.'">';
              $amountDueTotal = 0;
           for($record_count=0;$record_count<$record;$record_count++)
                { //loop for record count
                        ?>


            <tr>

               <td> 
                    <?php
                        $strDate = $node_date->nodeValue; //display the date of invoice (Date)
                        echo substr($strDate, -2) . '-' . substr($strDate, -4, 2) . '-' . substr($strDate, 0, 4);
                        //echo $node_date->nodeValue; //display the date of invoice (Date)
                    ?>
               </td>

               <td>
                   <?php
                       //echo $node_inv_no->nodeValue; //display the invoice number (DocumentID)
                       echo '<INPUT TYPE="text" NAME="eg_description_[]" Value="' . $invoiceArr[$record_count] . '" size="20"><br>';  //display the invoice number (DocumentID)
                    ?>   
               </td>

               <td>
                    <?php
                       echo '<INPUT TYPE="text" NAME="eg_payamt_[]" Value="' . $amount_dueArr[$record_count] . '" size="10"><br>';//display ammountDue (AmmountDue)                   
                       //echo $node_amount_due->nodeValue; //display ammountDue (AmmountDue)
                    ?>   
               </td>

               <td>
                    <?php
                       echo '<INPUT TYPE="text" NAME="eg_payamt_[]" Value="' . $TotalArr[$record_count] . '" size="10"><br>';//display outstanding (Total)                   
                       //echo $node_total->nodeValue; //display outstanding (Total)
                    ?>   
               </td>
               <td><input type="checkbox" name="pay[]" value="" onClick="calculateSum()"/></td>
            </tr>
            <tr>
               <td></td>

               <?php
                     $amountDueTotal += $amount_dueArr[$record_count]; //calculate the total ammount due
                       //Hidden fields
                      echo '<INPUT TYPE="hidden" NAME="eg_invoice_[]" Value="'.$invoiceNoArr[$record_count].'">';
                      echo '<INPUT TYPE="hidden" NAME="p_invage_[]" Value="'.$DateArr[$record_count].'">';
                }//end of the record count loop 

                ?>
            <tr>
               <td>Pay Ammount Not Listed Above</td>
               <td><input type="text" name="UnknownDocumentID" value="Invoice_unknown_docID_data" /></td>
               <!--<td><input type="text" name="Amount_Due_Unknown_Doc_ID" value="amount" size="10"/></td>--><!--Amount Due-->
               <td><input type="text" name="eg_payamt_[]" value="amount" size="10"/></td><!--Total-->
               <td></td>
               <td><input type="checkbox" name="pay[]" value="" onClick="calculateSum()"/></td>
            </tr>

                     <tr>
                        <td width="512px" colspan="5"><IMG SRC="rule-black.gif" WIDTH="800" HEIGHT="11"><br></td>
                     </tr>



               <td>Total ammount to pay</td>
               <td></td>
               <td></td>

                <td>
                    <!--<input type="text" name="total" value="<?php //echo $amountDueTotal;?>" />-->
                    <input type="text" name="totalNS" id="answer" value="" />
                    <INPUT TYPE="text" NAME="answer" id="answer" Value="" size="10"><br>

                </td>
             </tr> 

Payment after click, no result :
Payment after clicking checkbox

Am I writing the right code ?

<INPUT TYPE="text" name="answer" id="answer" Value="" size="10">

because when I put

document.write(sum);

****Got the answer :****

<script type="text/javascript">
    function checkTotal() {
        document.listForm.total.value = '';
        var sum = 0;
        for (i=0;i<document.listForm.choice.length;i++) {
          if (document.listForm.choice[i].checked) {
            sum = sum + parseInt(document.listForm.choice[i].value);
          }
        }
        document.listForm.total.value = sum;
    }
</script>

<form name="listForm">
<input type="checkbox" name="choice" value="2" onchange="checkTotal()"/>2<br/>
<input type="checkbox" name="choice" value="5" onchange="checkTotal()"/>5<br/>
<input type="checkbox" name="choice" value="10" onchange="checkTotal()"/>10<br/>
<input type="checkbox" name="choice" value="20" onchange="checkTotal()"/>20<br/>
Total: <input type="text" size="2" name="total" value="0"/>
</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-05-27T16:35:46+00:00Added an answer on May 27, 2026 at 4:35 pm

    Let’s work out on this below code..

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <INPUT TYPE="text" NAME="eg_payamt_[]" Value="" size="10"><br>
    
    <INPUT TYPE="text" NAME="eg_payamt_[]" Value="" size="10"><br>
    
    <INPUT TYPE="text" NAME="answer" id="answer" Value="" size="10"><br>
    
    <td><input type="checkbox" name="pay[]" value="" onclick="return calculateSum();" /></td>
    <script>
        function calculateSum() {
    
            var sum = 0;
            //iterate through each textboxes and add the values
           //$("input:text").each(function() {
           $("input[type='text'][name='eg_payamt_[]']").each(function(){ 
    
                //add only if the value is number
                if(!isNaN(this.value) && this.value.length!=0) {
                    sum += parseFloat(this.value);
                }
    
            });
    
            //.toFixed() method will roundoff the final sum to 2 decimal places
            $("#answer").val(sum.toFixed(2));
        }
    </script>
    

    This working fine for me..Check it out.

    Thanks.

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

Sidebar

Related Questions

I have a form a user can enter their name, then it will add
The following code will add the categories selector widget to the WordPress Page editor
I have a button that, when pressed, will add a new HTML row. Within
Why do I get only zero in my calculation? Code: <?php echo 'AU$ <input
I have a page when user can add 0 to N TinyMCE editors that
We are making a game which will add a level editor feature soon. We
I want to make a table in SqlServer that will add, on insert, a
Hi I need to extend the CListControl class in C++/MFC, which will add several
I'm working on a module that, among other things, will add some generic 'finder'
when will i add Advanced data grid in my project then it shows eror

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.