473,326 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Calculator Code Error? - First Ever Script

[HTML] <html>

<head>

<title></title>
<script type="javascript" src="E:\Internet\positive_gearing.js">
function positve_gearing() {

var price = form.price.value;
var rates = form.rates.value;
var bc = form.bc.value;
var rent = form.rent.value;
var ir = form.ir.value;

var a = (rates/52).toFixed(2);

if (bc > 500)
{
if (bc > 500)
var b = (bc / 52).toFixed(2);
}
else
var b = bc.toFixed(2);


if (rent > 5000)
{
if (rent > 5000)
var c = (rent / 52).toFixed(2);
}
else
var c = rent.toFixed(2);

var d = ((price*(ir/100))/52).toFixed(2);

var e = ((((c*50)-(c*50*0.08)-(bc*52)-rates)/price)*100).toFixed(2);
var f = (e-ir).toFixed(2);
var g = (c-d-b-a).toFixed(2);

form.a1.value = a;
form.b1.value = b;
form.c1.value = c;
form.d1.value = d;
form.e1.value = e;
form.f1.value = f;
form.g1.value = g;


return false;
}
</script>
</head>

<body>



<FORM NAME="myform" ACTION="" METHOD="GET"><table align="center"
border="1"><tr>

<td align="right">
Purchase Price:
</td>
<td align="left">
<input type="text" name="price" size="6" />
</td></tr><tr>

<td align="right">
Rates:
</td>
<td align="left">
<input type="text" name="rates" size="6" />
</td></tr><tr>

<td align="right">
Body/Corp (weekly or annually):
</td>
<td align="left">
<input type="text" name="bc" size="6" />
</td></tr><tr>

<td align="right">
Rent (weekly or annually):
</td>
<td align="left">
<input type="text" name="rent" size="6" />
</td></tr><tr>

<td align="right">
Interest rate:
</td>
<td align="left">
<input type="text" name="ir" size="6" />
</td></tr><tr>


<td colspan="2" align="center">
<INPUT TYPE="button" NAME="button1" Value="Calculate" onClick="positive_gearing()"></td></tr><tr>

<td align="right">
Rates (weekly):
</td>
<td alig="left">
<input type="text" name="a1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Body/Corp (weekly):
</td>
<td alig="left">
<input type="text" name="b1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Rent (weekly):
</td>
<td alig="left">
<input type="text" name="c1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Weekly Repayments (interest only):
</td>
<td alig="left">
<input type="text" name="d1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td HEIGHT="20" align="center"></td></tr><tr>

<td align="right">
Percent Return:
</td>
<td alig="left">
<input type="text" name="e1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Percent Profit/Loss:
</td>
<td alig="left">
<input type="text" name="f1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Weekly Profit/Loss:
</td>
<td alig="left">
<input type="text" name="g1" value="" size="6"
readonly="readonly" /></td></tr><tr>

</table>
</form>



</body>

</html>
[/HTML]
Mar 27 '07 #1
3 1626
r035198x
13,262 8TB
[HTML] <html>

<head>

<title></title>
<script type="javascript" src="E:\Internet\positive_gearing.js">
function positve_gearing() {

var price = form.price.value;
var rates = form.rates.value;
var bc = form.bc.value;
var rent = form.rent.value;
var ir = form.ir.value;

var a = (rates/52).toFixed(2);

if (bc > 500)
{
if (bc > 500)
var b = (bc / 52).toFixed(2);
}
else
var b = bc.toFixed(2);


if (rent > 5000)
{
if (rent > 5000)
var c = (rent / 52).toFixed(2);
}
else
var c = rent.toFixed(2);

var d = ((price*(ir/100))/52).toFixed(2);

var e = ((((c*50)-(c*50*0.08)-(bc*52)-rates)/price)*100).toFixed(2);
var f = (e-ir).toFixed(2);
var g = (c-d-b-a).toFixed(2);

form.a1.value = a;
form.b1.value = b;
form.c1.value = c;
form.d1.value = d;
form.e1.value = e;
form.f1.value = f;
form.g1.value = g;


return false;
}
</script>
</head>

<body>



<FORM NAME="myform" ACTION="" METHOD="GET"><table align="center"
border="1"><tr>

<td align="right">
Purchase Price:
</td>
<td align="left">
<input type="text" name="price" size="6" />
</td></tr><tr>

<td align="right">
Rates:
</td>
<td align="left">
<input type="text" name="rates" size="6" />
</td></tr><tr>

<td align="right">
Body/Corp (weekly or annually):
</td>
<td align="left">
<input type="text" name="bc" size="6" />
</td></tr><tr>

<td align="right">
Rent (weekly or annually):
</td>
<td align="left">
<input type="text" name="rent" size="6" />
</td></tr><tr>

<td align="right">
Interest rate:
</td>
<td align="left">
<input type="text" name="ir" size="6" />
</td></tr><tr>


<td colspan="2" align="center">
<INPUT TYPE="button" NAME="button1" Value="Calculate" onClick="positive_gearing()"></td></tr><tr>

<td align="right">
Rates (weekly):
</td>
<td alig="left">
<input type="text" name="a1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Body/Corp (weekly):
</td>
<td alig="left">
<input type="text" name="b1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Rent (weekly):
</td>
<td alig="left">
<input type="text" name="c1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Weekly Repayments (interest only):
</td>
<td alig="left">
<input type="text" name="d1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td HEIGHT="20" align="center"></td></tr><tr>

<td align="right">
Percent Return:
</td>
<td alig="left">
<input type="text" name="e1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Percent Profit/Loss:
</td>
<td alig="left">
<input type="text" name="f1" value="" size="6"
readonly="readonly" /></td></tr><tr>

<td align="right">
Weekly Profit/Loss:
</td>
<td alig="left">
<input type="text" name="g1" value="" size="6"
readonly="readonly" /></td></tr><tr>

</table>
</form>



</body>

</html>
[/HTML]
1.)Java != Javascript so I moved that to the Javascript forum.
2.)When posting code please use code tags like the ones I just added for you there.
3.)What did you say is the problem with your code?
Mar 27 '07 #2
Hi,

Yeah sorry pretty unclear was just in a hurry.

I'm not sure what is wrong with the code, just when i push the button to calculate it comes up with the error: object required for the line

Expand|Select|Wrap|Line Numbers
  1. INPUT TYPE="button" NAME="button1" Value="Calculate" onClick="positive_gearing()"></td></tr><tr>
Mar 28 '07 #3
acoder
16,027 Expert Mod 8TB
You're trying to access the form with the name "form".

Add this line to the beginning of your function:
Expand|Select|Wrap|Line Numbers
  1. var form = document.forms.myForm;
Also you've spelt "positive" incorrectly (an i is missing).
Mar 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
1
by: Eric Terrell | last post by:
Folks: I've posted the full source code to C# Programmable Calculator at my website: http://www.personalmicrocosms.com/html/cspcalc.html C# Programmable Calculator is a Reverse Polish...
5
by: Steven Smith | last post by:
I was flicking through the windows accesories programs for some inspiration for todays vb challenge when I came accross the calculator program & thought that looks easy I could do that. However...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
27
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
2
by: JasmynGomez | last post by:
This was an assignment for our JAVA class I am still a beginner and my code keeps getting errors, and I am so confused. I've tried every different way I can think of, can someone please take a...
1
by: clairelee0322 | last post by:
This program doesn't run because some problem with the reduce fraction. My reduce fraction is all right but when I tried to put that in this program, It has some errors. Or maybe the switch menu is...
4
by: Yonih | last post by:
So I am trying to get this Calculator to work. It needs to take in a vaule, and select a shipping Everythin works great except the shipping part. I need it to take the shipping value and add it to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.