Web Analytics Made Easy -
StatCounter calculate the balance - CodingForum

Announcement

Collapse
No announcement yet.

calculate the balance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • calculate the balance

    Hello all,

    How do I write a script to balance out the credit limit.


    1. Balance at the beginning of the month
    2. Total of all items charged for the month by the customer
    3. Total of all credits/payments applied to this account for this month
    4. Allowed credit limit

    calculate new balance (=beg balance + charges - credits), display the new balance and determine whether the new balance exceeds the customers credit limit. For those customers exceeding their credit limit, the program should output a message that tells the user they have exceeded their credit limit.

    Any help would be greatly appreciated. Thanks

  • #2
    This smells like homework. No?
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

    Comment


    • #3
      no, i'm trying to write a balance for my test page: Here is a code. But it's not work probably. Would you please take a look


      <html>

      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
      <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
      <meta name="ProgId" content="FrontPage.Editor.Document">
      <title>Total</title>
      </head>

      <body>
      <script language="javascript">
      <!--

      function calculate() {
      var creditlimit = 1000

      var balance = document.order.balance.value;
      var amount1 = document.order.amount1.value;
      var amount2 = document.order.amount2.value;
      var creditlimit = document.order.creditlimit.value;

      var x = (amount1 + balance);
      var total = x - amount2;
      var y = (total > creditlimit)? 'good balance' : 'credit limit are exceeded';
      document.order.consumption.value = x;
      document.order.supply.value = y;
      }



      // -->
      </script>


      <form name="order">
      Balance:<input type="text" name="balance" onchange="calculate()"><br>
      item charge:<input type="text" name="amount1" onchange="calculate()"><br>
      total credit:<input type="text" name="amount2" onchange="calculate()"><br>
      consumption:<input type="text" name="consumption" onchange="calculate()"><br>
      supply:<input type="text" name="supply" onchange="calculate()"><br>


      credit limit:<input type="text" name="creditlimit" value="1000" readonly>

      </form>

      </body>

      </html>

      Comment


      • #4
        I don't think your math is right, but you can solve that. The problem you were having was that you were retrieving the values form the form as strings, not numbers, so they were being concatenated, not added.

        Code:
        <html>
        
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
        <meta name="ProgId" content="FrontPage.Editor.Document">
        <title>Total</title>
        </head>
        
        <body>
        <script language="javascript">
        <!--
        
        function calculate( f )
        {
        	var creditlimit = 1000
        
        	var balance = parseInt( f.balance.value, 10 ) || 0;
        	var amount1 = parseInt( f.amount1.value, 10 ) || 0;
        	var amount2 = parseInt( f.amount2.value, 10 ) || 0;
        	var creditlimit = parseInt( f.creditlimit.value, 10 ) || 0;
        
        	var x = (amount1 + balance);
        	var total = x - amount2;
        	var y = (total > creditlimit)? 'good balance' : 'credit limit are exceeded';
        	f.consumption.value = x;
        	f.supply.value = y;
        }
        
        
        
        // -->
        </script>
        
        
        <form name="order">
        
        Balance:<input type="text" name="balance" onchange="calculate(this.form)"><br>
        item charge:<input type="text" name="amount1" onchange="calculate(this.form)"><br>
        total credit:<input type="text" name="amount2" onchange="calculate(this.form)"><br>
        consumption:<input type="text" name="consumption" onchange="calculate(this.form)"><br>
        supply:<input type="text" name="supply" onchange="calculate(this.form)"><br>
        credit limit:<input type="text" name="creditlimit" value="1000" readonly>
        
        </form>
        
        </body>
        
        </html>
        My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
        “Minds are like parachutes. They don't work unless they are open”
        “Maturity is simply knowing when to not be immature”

        Comment

        Working...
        X