Copy link to clipboard
Copied
I have a mortgage site that I inherited. I can enter the down payment at a certain dollar value. The owner wants to add the ability to either enter down payment (currently I have in site) or enter the percentage of a down payment. Below is where I need to add the code and what was in there to start.
<tr>
<td valign="middle"><div align="right">Down Payment:</div></td>
<td valign="middle"><span class="style6"></span></td>
<td valign="middle"><span class="style6">
<cfinput name="dPayment" type="text" tabindex="23" size="15" required="yes" message="Please enter the down payment amount." />
<!--- The down payment should be divided by the purchase price to determine the percentage of down payment (DP / PP = DP%) --->
</span></td>
</tr>
<!--- Entered 12/16/2018 --->
<tr>
<td valign="middle"><div align="right" class="style8">Or Enter</div></td>
<td valign="middle"><span class="style6"></span></td>
<td valign="middle"><span class="style6"></span></td>
</tr>
Need to know how to enter a percentage here. I am not a developer by any stretch of the imagination. Any help offered would be appreciated.
RasonJ77 wrote
That's fixed, now I get this when I put zero in for the dPayment. How to I set this to accept zero? Again, I apologize for my lack of coding skills.
<cfif baseLoanAmount>
<cfset baseLoanAmount = (purchasePrice - dPayment)>
<cfelse>
<cfset baseLoanAmount = (purchasePrice * dpPercentage) / 100>
</cfif>
For consistency in the calculations, you could change the definition of dpPercentage, as follows
<cfset purchasePrice = form.purchase>
<cfset dPayment = form.dPayment>
<!--- Added 12/31/2018
...Copy link to clipboard
Copied
rasonj77 wrote
I am not a developer by any stretch of the imagination.
This is a problem. Even if you are shown how to add HTML to add a form field that will accept a percentage, what are you going to add to the ColdFusion code that processes the submitted form? There is more to this than adding a bit of HTML.
I strongly suggest you hire a programmer.
Copy link to clipboard
Copied
I know. I told the owner this in the beginning, but he thought I could do this since I know enough to be dangerous when writing code.
I do have all the other cfm pages that pulls everything together; and I have been able to figure things out in the past, but this one has me stumped.
Copy link to clipboard
Copied
From what you've shown us, you could do the following in the action page of the form:
<cfset dpPercentage=(form.dPayment/form.pPrice)*100>
I have assumed dPayment and pPrice are input fields.
Copy link to clipboard
Copied
Thank you, I will try that.
Jason Retherford
Copy link to clipboard
Copied
heading the right path. Now I get "Element PERCENT is undefined in FORM"
<cfset purchasePrice = form.purchase>
<cfset dPayment = form.dPayment>
<!--- Added 12/31/2018 for precentage --->
<cfset dpPercentage = form.dpPercent>
Copy link to clipboard
Copied
Unless there is an input field named dpPercentage, it won't be in the form scope. The example BKBK​ presented sets a variable called dpPercentage, not a form field.
V/r,
^ _ ^
Copy link to clipboard
Copied
That's fixed, now I get this when I put zero in for the dPayment. How to I set this to accept zero? Again, I apologize for my lack of coding skills.
<cfif baseLoanAmount>
<cfset baseLoanAmount = (purchasePrice - dPayment)>
<cfelse>
<cfset baseLoanAmount = (purchasePrice * dpPercentage) / 100>
</cfif>
Copy link to clipboard
Copied
ColdFusion is a loosely typed language, which means that by default, 0 = "0" and it also = "false".. so your <cfif baseLoanAmount> is basically saying "If the value of baseLoanAmount is greater than 0", which is false if the value IS zero, so it goes to the cfelse. purchasePrice times zero divided by 100 is.. zero.
I'm leaving work, now. Have a Happy New Year.
V/r,
^ _ ^
Copy link to clipboard
Copied
Thank you; you too!
Copy link to clipboard
Copied
Now, I have to go down a set other loan amounts through the rest of the page. It looks like this may work. I will let you know how I made out.
Copy link to clipboard
Copied
RasonJ77 wrote
That's fixed, now I get this when I put zero in for the dPayment. How to I set this to accept zero? Again, I apologize for my lack of coding skills.
<cfif baseLoanAmount>
<cfset baseLoanAmount = (purchasePrice - dPayment)>
<cfelse>
<cfset baseLoanAmount = (purchasePrice * dpPercentage) / 100>
</cfif>
For consistency in the calculations, you could change the definition of dpPercentage, as follows
<cfset purchasePrice = form.purchase>
<cfset dPayment = form.dPayment>
<!--- Added 12/31/2018 for percentage --->
<cfset dpPercentage = (purchasePrice-dPayment)*100/purchasePrice>
The baseLoanAmount then follows from:
<!--- Sufficient definition of baseLoanAmount --->
<cfset baseLoanAmount = purchasePrice - dPayment>
<!--- Alternative definition of baseLoanAmount --->
<cfset baseLoanAmount = dpPercentage*purchasePrice/100>
Hence, when dPayment is zero, baseLoanAmount is the purchasePrice.
Happy New Year!
Copy link to clipboard
Copied
so I could have both of these in there at the same time?
Copy link to clipboard
Copied
ok, that worked (thank you!). Now it is causing another issue; since I have the baseLoanAmount set twice, the form is only looking at the first one. how do i get it to pick one or the other when running the form for mLoanAmount?
<!-Calculation for Mortgage Loan Amount->
Copy link to clipboard
Copied
<cfset baseLoanAmount = (purchasePrice - dPayment)>
<cfset baseLoanAmount = (dpPercentage*purchasePrice) /10>
<!---Calculation for Mortgage Loan Amount--->
<cfset mLoanAmount = (baseLoanAmount + upFrontMIP)>
Copy link to clipboard
Copied
I called the second one,
<!--- Alternative definition of baseLoanAmount --->
So use the one or, alternatively, the other.
Copy link to clipboard
Copied
that didn't work. it is only taking the first one. I can't get it to take one if there is a down payment entered like (10,000) or percentage like (10). Under Down Payment, I have a row to enter the percentage. I took it back out before I snipped this image.
Copy link to clipboard
Copied
RasonJ77 wrote
that didn't work. it is only taking the first one. I can't get it to take one if there is a down payment entered like (10,000) or percentage like (10). Under Down Payment, I have a row to enter the percentage. I took it back out before I snipped this image.
This confuses me a bit. To get back to the beginning, a form has been submitted. The definitions
<cfset purchasePrice = form.purchase>
<cfset dPayment = form.dPayment>
are on the action page of the form. These are required fields, so dPayment is available. If you want percentage to also be available here, then you should also include it as a form field.
Copy link to clipboard
Copied
it is in the form. I have both in there. Below is what is in the form and the added percentage.
Copy link to clipboard
Copied
Then I shall assume the form fields are, respectively, purchase, dPayment and dpPercentage. You could then proceed as follows:
<cfset purchasePrice = form.purchase>
<cfset dPayment = form.dPayment>
<cfset dpPercent = form.dpPercentage>
<cfif isNumeric(dpPercent)><!---If percentage submitted, use it to calculate down-payment --->
<cfset dPayment = dpPercent*purchasePrice/100>
<!---Convert to $ amount --->
<cfset dPayment = LSNumberFormat(dpayment, "$__.__")>
<cfelseif isNumeric(dPayment)><!---If down-payment submitted, use it to calculate percentage --->
<cfset dpPercent = (purchasePrice-dPayment)*100/purchasePrice>
</cfif>
Copy link to clipboard
Copied
You were correct, I was looking at it wrong! it is working as it should now. Thank you so much!