Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-29
4
Medium Priority
?
693 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:larrymurphy
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22835653

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

0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22835703
try:
<!-- Code shown below is from a responding ASP document to original HTML form. -->
<!-- code found in the <head> tag region -->
<% 
Function isInt(strInput)
  dim re, matches, match
  set re = new RegExp
  re.Pattern = "^\d+$"
  set match = re.Execute(strInput)
  if match.count > 0 then
  	checkPhone = true
  else
  	checkPhone = false
  end if
  set match = nothing
  set re = nothing
End Function 
Dim STRsaleprice,STRloanamt 
STRsaleprice= Trim( Replace( request("saleprice"),",","" ) )
STRloanamt= Trim( Replace( request("loanprice"),",","" ) ) 
If isInt(STRsaleprice) Then
	STRsaleprice = CInt(STRsaleprice)
Else
	STRsaleprice = 0
End If 
If isInt(STRloanamt) Then
	STRloanamt = CInt(STRloanamt)
Else
	STRloanamt = 0
End If
%>
 
<!-- 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

0
 

Author Closing Comment

by:larrymurphy
ID: 31511398
Expert comment was formatted and answered as the question was posed. It did not leave anything to doubt.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22840737
glad to help
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question