Search the Community
Showing results for tags 'javascript onkeyup php mysql'.
-
I am using the wonderful onkeyup argument to auto update values in forms. I have a question though. Example: I have five values. Loan, Terms, Saldo, Payment, Interest The form is built up that it gets its data from a database. The Loan, Terms and Interest rate will be entered as a default value to handle the rest of the terms, payment and saldo. example: loan = 1000, terms = 12 Interest = 215 Saldo = Loan = 1000 The form will be filled in as an overview of payments and saldo, to check how much money still needs to be paid. For the next entry, the term will count down 1, and I can enter a payment, example 102. Paying a payment will first influence the interest amount until it is 0. From that moment on the Saldo will go down from it's default value of a 1000. Until it is zero I have managed to auto update my form entries automatically when a payment is entered, so that the Interest goes down accordingly. Everytime the payment in this example should be 102. At a certain moment the interest will drop from 215 to 113 to 11. But then I am stuck. Added below is a part of the code. The calculation and check should be done right after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. I know the code is not correct, because at its current state, it won't touch the value of Loan when interest = 0. Not knowing how to catch this, the interest will just become negative. Is there a way to deduct and thus update the form fields in such a matter that when the interest hits 0 the remainder of the payment will be deducted from the Saldo value and in the process keep my form fields being auto updated? Thanks! Mike <?php // Generate split between Interest bigger or equal to zero if (!empty($loan) and $interest >= 0) { // fill in or echo the size of the loan if (!empty($loan)) { echo '<input type="text" size="11" name="loan" value = '.$loan.'></div></td>'; } else { echo '<input type="text" size="11" name="loan" value="" /></div></td>'; } echo '<td><div align="center">'; } // Fill in the payment and deduct it from interest as long as interest is bigger than 0. if (!empty($interest)) { echo '<input type="text" size="11" name="payment" onkeyup="document.forms[0].interest.value = '.$interest.'*1 - document.forms[0].payment.value*1;"></div></td> <td><div align="center"><input type="text" size="11" name="saldo" value="'.$loan.'" readonly="readonly" />'; } else { echo '<input type="text" size="11" name="payment" value="" /></div></td>'; echo '<td><div align="center"><input type="text" size="11" name="impru_sold" />'; } echo '</div></td><td><div align="center">'; ?> I stopped entering the code here, because it is quite long, and the magic should happen after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. If more code is needed, I will be happy to enter it here.