Midevil Chaos, on 28 July 2012 - 07:48 PM, said:
I have a problem of sorts. I am trying to do a mortgage calculator.
within the last pair of parentheses in the second "if" (on the first line of that "if"), i need a greater than statement. It has to state that the value of the down_payment variable cannot be greater than 51% of the property_value variable. I have no idea how to state such a thing using a boolean statement. (Note that all of this will be done DURING the validation phase).
if (property_value.value == "" || isNaN(property_value.value) || (property_value.value <= 60000)){
property_value.style.border = "red solid 2px";
valid = false;
}if (down_payment.value == "" || isNaN(down_payment.value) || (){
down_payment.style.border = "red solid 2px";
valid = false;}
Hey there Midevil,
I hope I am understanding your question correctly, you would like to execute the last "if statement" if the variable down_payment's value is greater than 51%, although I don't understand the relation to property_value... This is assuming that down_payment variable is sorting a type integer from 0 to 100 for the comparison of a percentage.
var dp = down_payment.value;
if (dp > 51 || dp == "" || isNaN(dp)) {
down_payment.style.border = "red solid 2px";
valid = false;
}
I hope this is the code you looking for, again this is assuming the down_payment value is between 0 and 100 to make up a percentage. If it is not, you can simply make another variable to store the percentage calculated from which ever variables you use to make up the percentage. The basic comparison operators are:
Equal : ==
Greater Than : >
Less Than : <
Greater/Equal To : >=
Smaller/Equal To : <=
Please let me know if this is what you were looking for and if you require anything else.
Peace Out