Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Subtracting to leave the balance

    Can anyone help.

    I have a html form that has 3 fields - "Fee", "Advanced Fee" and "Balance Due"

    Can someone help me work out a bit of JS that when the "Fee" in entered in a whole number it will subtract the "Advanced Fee" to leave the "Balance Due" but can this be done in automatically.

    Here is my form.

    Code:
    <b><font size="2" face="Arial">Payment Info.</font></b>
    <form method="POST" action="ad.asp">
        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="572" height="23" id="AutoNumber3">
          <tr>
            <td width="180" height="5" align="right" bgcolor="#336699"><b><font size="2" face="Arial" color="#FFFFFF">Fee
              :</font></b></td>
            <td width="386" height="5"><font size="2" face="Arial">
            <b>&nbsp;£<input type="text" name="Fee" size="20" tabindex="15"></b></font></td>
          </tr>
          <tr>
            <td width="180" height="11" align="right" bgcolor="#336699"><b><font size="2" face="Arial" color="#FFFFFF">Advanced
              Fee :</font></b></td>
            <td width="386" height="11"><font size="2" face="Arial">
            <b>&nbsp;£<input type="text" name="Advanced_Fee" size="20" tabindex="16"></b></font></td>
          </tr>
          <tr>
            <td width="180" height="20" align="right" bgcolor="#336699"><b><font size="2" face="Arial" color="#FFFFFF">Balance
              Due :</font></b></td>
            <td width="386" height="20"><font size="2" face="Arial">
            <b>&nbsp;£<input type="text" name="Balance_Due" size="20" tabindex="17">&nbsp;&nbsp;
            </b></font></td>
          </tr>
          <tr>
            <td width="180" height="18" align="right" bgcolor="#336699">
            <font size="2" face="Arial" color="#FFFFFF">
              <b>When:</b></font></td>
            <td width="386" height="18"><font face="Arial" size="2"><b>&nbsp;£</b><input type="text" name="Balance_Due_When" size="7" style="text-transform: uppercase" tabindex="18">i.e OTN = <b>O</b>n <b>T</b>he<b> N</b>ight</font></td>
          </tr>
        </table>
      </form>
    Kind regards,
    Mike Hughes

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Subtract the advanced fee from what?? You do not have any values, default or otherwise within your form codes...

    But to anser your question, use the onchange event handler on the fee input and check if the value.length is more than zero and do your calculations depending upon the value.length being zero or more than zero....

    .....Willy

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I want to subtract the "advanced fee" from the "fee" the fee will be manually typed in by me.

    I.e

    fee - advanced fee = balance due
    Kind regards,
    Mike Hughes

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hughesmi
    I want to subtract the "advanced fee" from the "fee" the fee will be manually typed in by me.

    I.e

    fee - advanced fee = balance due
    Simple, to the point and assuming you know to input the advanced fee value first so you have something to subtract from...

    <input type="text" name="Fee" size="20" tabindex="15"
    onkeyup="this.form.Balance_Due.value=this.form.Advanced_Fee.value/1-this.value/1">

    .....Willy

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Willy thanks for your help.

    But the "Balance Due" is showing as a negtive numer i.e -100

    What do I need to swap it around?
    Kind regards,
    Mike Hughes

  • #6
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Make sure something is entered into the advanced fee field before you enter your Fee value...

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    i did and balance comes out as a - number

    exapmle

    Adavanced Fee = 150
    Fee = 250

    150 - 250 = -100

    I just realised it's not Advanced Fee - Fee. It Shoulds be Fee - Advanced Fee = Blanace Due
    Kind regards,
    Mike Hughes

  • #8
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Read this again:
    Quote Originally Posted by Willy Duitt
    Simple, to the point and assuming you know to input the advanced fee value first so you have something to subtract from...

    <input type="text" name="Fee" size="20" tabindex="15"
    onkeyup="this.form.Balance_Due.value=this.form.Advanced_Fee.value/1-this.value/1">

    .....Willy
    The line that says "to the point and assuming you know to input the advanced fee value first so you have something to subtract from..." If you input the advanced fee value first, it works...but by looking at the code given to you, you can figure out to switch them however you like...
    <input type="text" name="Advanced_Fee" size="20" tabindex="16" onkeyup="this.form.Balance_Due.value=this.form.Fee.value/1-this.value/1">

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I had understood it the first time round.

    Your last script got thanks;- it working sweet!!!!
    Kind regards,
    Mike Hughes


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •