Link to home
Start Free TrialLog in
Avatar of larrymurphy
larrymurphyFlag for United States of America

asked on

How to write Classic ASP to compare two form fields as numeric values?

How do I write ASP code to compare two form fields as numeric values, then produce output based on one being greater than or equal to the second field, using Classic ASP?

Situation: Field one is sale price and field two is a loan amount. If the loan amount is more than the sale price, then I want the user to return to the field and correct the loan amount to be under the sale price. However, if the sale price is greater than or equal to the loan amount, then accept the field input as it is.

Problem: The sale price is 100,000 and the loan amount is 80,000. These values are being interrupted as characters instead of numbers resulting in showing 8 as greater than 1. I need the comparison to be returned based on numeric values where 80,000 is less than 100,000.

Solution: What can I do?
<!-- Code shown below is from a responding ASP document to original HTML form. -->
<!-- code found in the <head> tag region -->
<% 
Dim STRsaleprice,STRloanamt
STRsaleprice=request("saleprice")
STRloanamt=request("loanprice")
%>
 
<!-- code found in the <body> tag region -->
<% if (STRsaleprice >= STRloanamt) then %>
  <p><label for='txtbox2'><em>What is the estimated sale price/value of the property?*</em></label> $ <input type='text' name='saleprice' size='20' maxlength='12' id='txtbox2' tabindex='18' style='background-color:#ffc;' value='<%= STRsaleprice %>' /></p>
  <p><label for='txtbox3'><em>How much do you want to borrow?*</em></label> $ <input type='text' name='loanamt' size='20' maxlength='12' tabindex='19' id='txtbox3' style='background-color:#ffc;' value='<%= STRloanamt %>' /></p>
<% else %>
  <p class='12x'><label for='txtbox2'><em><span class='color:red;font-weight:bold;'>What is the estimated sale price/value of the property?*</span></em></label> $ <input type='text' name='saleprice' size='20' maxlength='12' class='14x' id='txtbox2' tabindex='18' style='background-color:#fecaca;' value='<%= STRsaleprice %>' /> <span style='color:blue;'>Sale price/property value is lower than the loan request amount shown below.</span></p>
  <p class='12x'><label for='txtbox2'><em><span class='color:red;font-weight:bold;'>How much do you want to borrow?*</span></em></label> $ <input type='text' name='loanamt' size='20' maxlength='12' class='14x' id='txtbox2' tabindex='19' style='background-color:#fecaca;' value='<%= STRloanamt %>' /> <span style='color:blue;'>Reduce your loan request to be less than sale price/property value. Please try again!</span></p>
<% end if %>

Open in new window

Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image


if STRloanamt=request("loanprice") > STRsaleprice=request("saleprice") then
  response.write "You cannot get a loan for more than the sales price! Please go back it correct your data."
  response.end 'Not the best, but it does keep the rest of the page from loading.
end if

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of larrymurphy

ASKER

Expert comment was formatted and answered as the question was posed. It did not leave anything to doubt.
glad to help