Click to See Complete Forum and Search --> : Hi all can i borrow an expert please


deedee
07-28-2003, 05:50 PM
Hi

Below i have posted u what i have created so far which isnt much other than a layout design.. The user can come to this page and enter how many cd's per month they purchase and then it will display in three seperate fields how much its costing them per year, per 5 years, per 10 years. The basic calculations are;

(input) * 13.99 * 12
(input) * 13.99 * 60
(input) * 13.99 * 120

13.99 is the national average cost per CD (so says a media magazine)

I am sure that i have to use javascript to make the calculations but i am not sure of anything else. Any pointers or even tutorials or sites of interest around the net would be appericated. As i would like to know more about this subject to help others.

<td colspan="5" valign="top" bgcolor="#CCCCCC"><div align="center"><strong>CD Cost Calculator</strong></div>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="5" valign="top" bgcolor="#FFFFCC"><div align="center"><font size="2">How Many CD's Do You Purchase Each Month (Average)<br>
</font>
<form name="CD Calc" method="post" action=""><font size="2">
<input name="CD" type="text" size="4" maxlength="4">
</font> </form>
</div>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td valign="top" bgcolor="#FFFFCC"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td valign="top" bgcolor="#FFFFCC"><div align="center"><font size="2"><strong>Yearly</strong></font></div>
</td>
<td valign="top" bgcolor="#FFFFCC"> <div align="center"><font size="2"><strong>5 Years</strong></font></div>
</td>
<td valign="top" bgcolor="#FFFFCC"><div align="center"><font size="2"><strong>10 Years</strong></font></div>
</td>
<td valign="top" bgcolor="#FFFFCC"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="5" valign="top" bgcolor="#FFFFCC"><form name="Result" method="post" action="">
<div align="center">
<input type="text" name="Yearly">
<input type="text" name="5 Years">
<input type="text" name="10 Years">
</div>
</form>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="5" valign="top" bgcolor="#CCCCCC"><div align="center"><font size="2">* National Average Compact
Disc Costs = 13.99</font></div>
</td>

With Thanks
Dee

pyro
07-28-2003, 05:57 PM
Try something like this:

<script type="text/javascript">
function calculate(frm) {
price = parseFloat(frm.num.value);
frm.price_year.value = "$" + (price * 13.99 * 12).toFixed(2);
frm.price_5year.value = "$" + (price * 13.99 * 60).toFixed(2);
frm.price_10year.value = "$" + (price * 13.99 * 120).toFixed(2);
}
</script>

</head>

<body>
<form name="myform">
Number of CD's purchased per month: <input type="text" name="num"><br>
Price per year: <input type="text" name="price_year"><br>
Price per 5 years: <input type="text" name="price_5year"><br>
Price per 10 years: <input type="text" name="price_10year"><br>
<input type="button" value="Calculate" onclick="calculate(this.form);">
</form>

deedee
07-28-2003, 06:11 PM
Thank you very much that worked a treat... Could u advise a good book for me to read that i can dust up on Javascript...

Take Care
Dee

pyro
07-28-2003, 06:32 PM
I'd recommend "JavaScript, The Definitive Guide" by David Flanagan and http://devedge.netscape.com/library/manuals/2000/javascript/1.3/guide/