Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:33:01+00:00 2026-06-01T20:33:01+00:00

I am having two issues that I have not been able to figure out.

  • 0

I am having two issues that I have not been able to figure out. I am using javascript to calculate compound interest. My formula for calculating the interest works, but I need a tabular interest rate schedule to appear after the calculations (to show period by period the amount of money accrued each time) and then a final total and total interest amount. This is what my code looks like:

<head>
    <title></title>
<script type="text/javascript">
    function rateSched(amnt, prd, rte, namt) {
        for (i = 0; i < periods; i++) {
            if (!document.getElementsByTagName) return;
            tabBody = document.getElementsByTagName("tbody").item(0);
            row = document.createElement("tr");
            cell1 = document.createElement("td");
            cell2 = document.createElement("td");
            cell3 = document.createElement("td");
            cell4 = document.createElement("td");
            textnode1 = document.createTextNode(amnt);
            textnode2 = document.createTextNode(prd);
            textnode3 = document.createTextNode(rte);
            textnode4 = document.createTextNode(namt);
            cell1.appendChild(textnode1);
            cell2.appendChild(textnode2);
            cell3.appendChild(textnode3);
            cell4.appendChild(textnode4);
            row.appendChild(cell1);
            row.appendChild(cell2);
            row.appendChild(cell3);
            row.appendChild(cell4);
            tabBody.appendChild(row);
        } 
    }
    var deposit;
    var periods;
    var interest;
    var newamount = deposit * (Math.pow(1 + interest, periods) - 1) / interest;
    var i=0;

    function calcAmt(form1) {
        deposit = form1.dp.value;
        interest = form1.rt.value;
        periods = form1.pr.value;
        form1.amt.value = Math.round(deposit * (Math.pow((1 + interest / 100), periods)) * 100) / 100;
        form1.intr.value = Math.round((deposit * (Math.pow((1 + interest / 100), periods)) - deposit) * 100) / 100
    }
</script>
</head>
<body>
<center>
    <form method="get" name="form1" onreset="form1.dp.focus()">

    <table border="5" bgcolor="#BDBDBD" cellpadding="2" width="300px">
    <tr><td colspan="2" align="center">
    <b><font size="5" color="#4B088A">Compound Interest</font></b>
    </td></tr>

    <tr><td align="right">Initial Deposit</td><td>
    <input type="text" name="dp" value=""/></td></tr>

    <tr><td align="right">Interest Rate (% Value)</td><td>
    <input type="text" name="rt" value=""/></td></tr>

    <tr><td align="right">Periods</td><td>
    <input type="text" name="pr" value=""/></td></tr>

    <tr><td align="right">Final Amount</td><td>
    <input type="text" name="amt" value=""/></td></tr>

    <tr><td align="right">Total Interest</td><td>
    <input type="text" name="intr" value=""/></td></tr>

    <tr><td>
    <input type="button" name="calc" value="Calculate" size="13" onclick="calcAmt(form1);rateSched(deposit,interest,i,newamount);return false;"/></td>

    <td></td></tr>
    </table>
    </form>

    <br />

    <table border='1' width="300px">
    <tbody>
    <tr><td>Amount</td><td>Period</td><td>Rate</td><td>New Amount</td></tr>
    </tbody>
    </table>

    <br />

    <table>
    <tr><td align="right">Final Amount</td><td>
    <input type="text" name="amt" value="" size="13"/></td></tr>

    <tr><td align="right">Total Interest</td><td>
    <input type="text" name="intr" value="" size="13"/></td></tr>
    </table>

    </center>
</body>
</html>

My problems are that the new table rows should be appended to the lower, four column table instead of the upper one, they should display each period as it goes instead of identical columns, and the bottom “Final Amount” and “Total Interest” do not fill in with the onclick.

Edit: Latest version of code having troubles with as described in comments:

function calcAmt(form1) { 
    var newamount = deposit * (Math.pow(1 + interest, periods) - 1) / interest; 
    deposit = form1.dp.value; 
    interest = form1.rt.value; 
    periods = form1.pr.value; 
    form1.amt.value = Math.round(deposit * (Math.pow((1 + interest / 100), periods)) * 100) / 100; 
    form1.intr.value = Math.round((deposit * (Math.pow((1 + interest / 100), periods)) - deposit) * 100) / 100 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:33:02+00:00Added an answer on June 1, 2026 at 8:33 pm

    To target the right tbody tag, you should put an ID on it and use document.getElementById("xxx") as this will guarentee you get the right one without relying on a particular position index in your HTML document.

    FYI, all tables have a tbody tag whether it’s in your HTML or not.

    You can see how I use document.getElementById("results") to get the results going into the right table here: http://jsfiddle.net/jfriend00/MqMtd/

    Also, all variables inside a function that you intend to be local variables (not globals) should have var in front of them. You are using a lot of implicit globals (variables never explicitly declared) which is a very bad practice.

    The value of newAmount is not valid because the code that initializes it runs before the variables that it depends on are filling in. I’d suggest you set the value of newAmount in calcAmt() where the other values it depends upon are set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Javascript I have been able to select an image element (an HTMLImageElement object,
We are having two load balancing server. In that we have hosted a asp.net
I have been working with pyinotify and I am having issues with it where
I am having two issues: I usually create separate view for the login to
I'm having two jquery's that I run and I want to combine them both
There are a number of issues i'm having, all being related. Some I have
Quick question that requires a long explanation.. Say I have two tables - one
We have a bunch of VB6 applications that access two different database servers (both
Here is the issue I am having: I have a large query that needs
I have a problem that has been a thorn in my side for nearly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.