this is really a client side functionality.
use javascript for it. here's something i made to do rough interest calculations. you should be able to modify it for your purpose.
<html>
<head>
<title>intrest estimator</title>
</head>
<body>
<p><h1>This is rough-estimate earning calculator. It forgoes some things such as compounding interest. It also calculates only by full year.</h1>
<!-- this is a list of instructions on use -->
<p>
<nl>Instructions on use of Calculator
<li>write yearly deposit amount<sup><font size=-1>1</font></sup> in text field marked "Deposit Amt."
<li>write yearly intrest rate<sup><font size=-1>2</font></sup> in feild marked "Interest Rate"
<li>write number of years<sup><font size=-1>3</font></sup> you wish to leave it in the bank in field marked "Term"
<li>leave the "Final Amount" field as is.
<li>push the calculate button
</nl>
<!-- list of restrictions -->
<br>1: must be a positive integer greater than or equal to 1 with no more than two decimal places.
<br>2: must be between 0.00 and 20.00 inclusive. The default interest rate is 0%. this will be used if no interest rate is provided.
<br>3: this can be as low as 1 year.
<p>
<!-- form with a table nested in it to give clarity and alignment -->
<form name="intCalc">
<table cell border=1 cell padding=%1>
<tr>
<td>if one places $</td>
<td><input type=text name=deposit size=10 value="Deposit Amt.">
<td>per year
</tr><tr>
<td>at an intrest rate of
<td><input type=text name=intrest size=10 value="Interest Rate">
<td>% per year
</tr><tr>
<td>for a total of
<td><input type=text name=yrs size=10 value="Term">
<td>years
</tr><tr>
<td>one will have $
<td><input type=text name=amt size=10 value="Final Amount">
<td>at the time of withdrawl
</tr><tr>
<td>
<td align=center><input type=button value=calculate onClick=calculate()>
<td>
</tr>
</table>
</form>
<!-- script that checks the variables and does the calculation -->
<script language="JavaScript">
function calculate(){
/* first grab the three variables that will be used */
var dep=(document.intCalc.deposit.value *1);
var rate=(document.intCalc.intrest.value *1);
var length=(document.intCalc.yrs.value *1);
var total=0;
/* then check to make sure they are valid */
if (dep==null){ //check to make sure there's a deposit
alert("Please enter a deposit amount.")};
else if ((dep*100)<100){ // if so make sure it's not too low
alert("The yearly deposit is too low")};
else if (((dep*100)-Math.round(dep*100))>0){ // make sure there's no fractions of a penny
alert("You can't deposit fractions of a penny")};
// else if (b=="Interest Rate"){
alert("You forgot to negotiate an interest rate.")};
else if (((rate*100)<0)||((rate*100)>2000)){ // make sure it is valid
alert("The rate is invalid")};
// else if (c=="Term"){
alert("You forgot to set a Term.")};
else if (length==null){ // check for the number of years they want it held
alert("Please enter the number of years your money will be in the bank's possesion")};
else if (length<1){ // make sure it's at least a year
alert("This bank will not hold onto your money for less than a year.")};
else if ((length-Math.round(length))>0){ // and that it's not got some weird fraction
alert("That includes a fraction of a year please decide how many YEARS you would like it deposited for. We don't try to guess how you divided the year into decimal form.")};
/* if all that is valid, then calculate the value */
else {rate=(rate/100)+1; //make the 1.x% so that when multiplied by the total it will yeild the result
/* then calculate the amount... */
for(i=0; i<length; i++){
total=(total+dep)*rate;};
/* ... and return it to the user */
document.intCalc.amt.value=Math.round(100*total)/100; //this makes sure there are only 2 decimal places.
};}
</script>
</body>
</html>
the comments in the code explain what each section does. you should be able to modify it without much issue if you know simple javascript. i never really got into it and was able to whip that up in 15 minutes for a friend a long time ago (it might be compliant with a javascript revision one step back)