...

View Full Version : Subtracting to leave the balance



hughesmi
02-01-2005, 05:54 PM
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.



<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>

Willy Duitt
02-01-2005, 06:35 PM
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

hughesmi
02-01-2005, 06:41 PM
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

Willy Duitt
02-01-2005, 06:48 PM
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

hughesmi
02-01-2005, 06:59 PM
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?

Brandoe85
02-01-2005, 07:22 PM
Make sure something is entered into the advanced fee field before you enter your Fee value...

hughesmi
02-01-2005, 07:28 PM
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

Brandoe85
02-01-2005, 07:39 PM
Read this again:

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">

hughesmi
02-01-2005, 07:45 PM
I had understood it the first time round. :o

Your last script got thanks;- it working sweet!!!! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum