Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-15-2011, 07:23 PM   PM User | #1
czv7285608
New to the CF scene

 
Join Date: Apr 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
czv7285608 is an unknown quantity at this point
Hi, all: I need help with this question

Hi, all:
I've been trying to insert a Loop into my javascript codes so that for the table I am creating :
every previous year's ending total amount becomes next year's beginning principal. The webpage interface should be like:
PHP Code:
a button functions a calculation here says "Calculate"
Principal          Period            Rate              Total Amount
input txtbox     input txtbox    input txtbox 
so, if the user input "8" into the period textbox, the output should generate 8 additional rows displaying every year's amount.

create a Web site made up a single or two pages depending on how you implement it. That page(s) will use JavaScript to calculate the interest on a savings account. The page should have an input section in which the user enters the following values:
The initial amount deposited in a savings account.
The number of periods.
The interest rate per period.
Create a button on the page. When the user clicks the button, you should create a tabular interest rate schedule such that there is one row for each period. This table output might look something like:
PHP Code:
Principal   Period  Rate    Total Amount 
100.00      1       0.01     101.00 
101.00      2       0.01     102.01 
...            ...       ...        ...
... 
Adhere to the following as you create the page(s)

You can display the output in either a table or you can use CSS.
Below the table, display the total interest received.
You can display the table in a new Web page or on the same Web page containing the input controls.
Make sure that the page(s) are well-formed and well formatted.

I will be grateful if you help me out. Honestly, it took me days, I still can not figure it out. so sad.

Last edited by czv7285608; 04-15-2011 at 07:38 PM..
czv7285608 is offline   Reply With Quote
Old 04-15-2011, 09:26 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
You are going to have to post some code examples before anyone can help you.
DanInMa is offline   Reply With Quote
Old 04-16-2011, 01:55 AM   PM User | #3
czv7285608
New to the CF scene

 
Join Date: Apr 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
czv7285608 is an unknown quantity at this point
I messed it up, so my code does not generate the headers. and does no calculation.

<head>
<title></title>
<script type="text/javascript">

var x = document.getElementById("tblDemo");
x.style.border = "solid";
x.style.borderColor = "#FFFFCC";
x.style.backgroundColor = "#CCFFCC";

var row = x.insertRow();
row.style.width = "200px";
row.style.border = "solid";
row.style.borderColor = "gray";

var cell = row.insertCell();
cell.style.width = "300px";
cell.style.textAligh = "";
cell.style.border = "solid";
cell.style.borderColor = "#00CC99";
cell.innerHTML = "Amount";

var cell = row.insertCell();
cell.style.width = "300px";
cell.style.textAligh = "";
cell.style.border = "solid";
cell.style.borderColor = "#00CC99";
cell.innerHTML = "Period";

var cell = row.insertCell();
cell.style.width = "300px";
cell.style.textAligh = "";
cell.style.border = "solid";
cell.style.borderColor = "#00CC99";
cell.innerHTML = "Rate";
var cell = row.insertCell();
cell.style.width = "300px";
cell.style.textAligh = "";
cell.style.border = "solid";
cell.style.borderColor = "#00CC99";
cell.innerHTML = "New Amount";


var principle = document.forms["Myform"]["principle"].value
var period = document.forms["Myform"]["period"].value
var rate = document.forms["Myform"]["rate"].value

}
function calculate () {
newamount = principle * ((rate / 100) + 1)


}

</script>
</head>
<body>
<table id="tblDemo">
</table>
<form name="Myform" action="">
<fieldset>
<input type="text" name="principle" />
<input type="text" name="period" />
<input type="text" name="rate" />
<input type="button" value="Create Table" />

</fieldset>

<fieldset>
<input type="button" id="calculate" value="Calculation"
onclick="createRow ()" />

</fieldset>


</form>

</body>
czv7285608 is offline   Reply With Quote
Old 04-16-2011, 12:33 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Form element values are returned as text:
Code:
var principle = parseFloat(document.forms["Myform"]["principle"].value);
var period = parseInt(document.forms["Myform"]["period"].value);
var rate = parseFloat(document.forms["Myform"]["rate"].value);
Code:
onclick="createRow ()" /> <!-- delete the space before () -->
I assume you've omitted 'function createRow() {' from your JavaScript when copying and pasting?
AndrewGSW is offline   Reply With Quote
Old 04-16-2011, 05:38 PM   PM User | #5
czv7285608
New to the CF scene

 
Join Date: Apr 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
czv7285608 is an unknown quantity at this point
Ok, but how to do the loop? l think it deals with Dim variables. I do not know how that works. Would somebody post the actual complete code to show me?
czv7285608 is offline   Reply With Quote
Old 04-16-2011, 11:36 PM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Would somebody post the actual complete code to show me?
Homework.. ?!

JavasScript doesn't use 'Dim' - that's Visual Basic - it uses 'var'.

The following demonstrates a looping structure:
Code:
function createRows(noOfRows) {
    var x;
    for (x=0; x < noOfRows; x++ ) {
        // obtain or calculate principal, period, etc..
        // add a row to the table, 
        // inserting the principal, etc., into the correct cells as you go
        // (you already have some code that inserts a row)
    }
}
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:11 AM.


Advertisement
Log in to turn off these ads.