Click to See Complete Forum and Search --> : Please review my Real Estate Calculator


assertivewd
05-20-2005, 01:29 PM
http://www.assertivead.com/calc



function numbers(){

var closingCosts = financing*.03;
var afiFee = financing*.03;
var cashBack = financing - closingCosts - costValue - afiFee;
var escrow = financing*.01*escrowLength;
var inHand = cashBack-escrow;
var equity = propValue - financingValue;
var financingValue = propValue*financing;

var costValue = financialcalc.costValue.value;
var propValue = 240000;
var financing = financialcalc.financing.value;

var escrowLength = 3;
}




This doesn't seem to be working like it should. I am not sure what I need to do. I have made sure all of the variables and corresponding text boxes the same. Do I have to somehow tell it to write to the boxes? Or am I missing something altogether? The code for the form is failry long so you can view the source for that information, or if it would be easier for me to post it, let me know and I will do so.

Keep in mind I have no experience in this aside from what you see here. I made this off of one of the only tutorials I could find for calculators (theirs made and easter day calculator). I do have a good sense of coding though, so I am not completley hopless.

So for my question: "What am I missing?"

Thanks for the help!

Natcon67
05-20-2005, 01:48 PM
this might be a good start:


function numbers(){
var form = document.financialcalc; //save the form name to a var

var financing = form.elements['financing'].value; //get the financing value
var closingCosts = financing*.03;
var afiFee = financing*.03;
var costValue = form.elements['costValue'].value; //get the cost value
var cashBack = financing - closingCosts - costValue - afiFee;
var escrowLength = 3;
var escrow = financing*.01*escrowLength;
var inHand = cashBack-escrow;
var propValue = 240000;

var financingValue = propValue*financing;
var equity = propValue - financingValue;

//SAVE THE CALCULATION BACK TO THE TEXT BOXES
form.elements['financingValue'].value = financingValue;
form.elements['cashBack'].value = cashBack;
form.elements['escrow'].value = escrow;
form.elements['inHand'].value = inHand;
form.elements['equity'].value = equity;

}


disclaimer: I havent been doing this for very long, so there might be a better way of doing it!

assertivewd
05-20-2005, 04:42 PM
thanks guy, that seemed to work! Now a bunch of the fields aren't doing what their supposed to.

It doesn't seem to read the financing, value or variable and replacing with either nothing or 1.

Juuitchan
05-23-2005, 12:26 PM
JavaScript variables are perverse. Very perverse.

First of all, there is absolutely no relation between the kind of JavaScript variable you apparently want and the text in a textbox. Sure, you can have JavaScript read from textboxes and write to textboxes, but there are limitations to this.

First of all, when you read from a textbox, it is always a STRING, never numeric. Perhaps the most important difference between strings and numerics is this: does 2+2 equal 4 or 22?

You have other issues to consider: If I type an amount with commas, or with a dollar sign, how will you handle that? I think you might need a special function to extract the text from a textbox and convert it into a numeric value.

assertivewd
05-23-2005, 01:04 PM
Thanks Natcon67 for the script, it seems to work like it should now that I ahve tweeked it slightly. The only problem was that the variables seem to be dependent on the order they are in the code. (ie, if financingValue isn't defined before equity, it returns an error)

As for typing amounts, it will purely drop-down powered so they must select a pre-determined value.

Heres a link to it: www.assertivead.com/calc

I am still having a problem with the closingCosts and afiFee boxes, they had updated for me for a few times, and them started to display nothing. I'm not sure why, but I do not know if this has to do with order as well. I tried rearranging them, and couldn't find a solution. Any ideas?


var form = (document.financialcalc); //save the form name to a var
var financing = (form.elements['financing'].value)/100; //get the financing value
var propValue = (240000);
var financingValue = (propValue * financing);
var equity = (propValue - financingValue);
var closingCosts = (financingValue * .03);
var afiFee = (financingValue * .03);
var costValue = (form.elements['costValue'].value); //get the cost value
var cashBack = (financingValue - closingCosts - costValue - afiFee);
var escrowLength = (3);
var escrow = (financingValue * .01 * escrowLength);
var inHand = (cashBack - escrow);


Thanks again for the help!