Solved

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

Posted on 2008-10-29
4
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 125 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with query 3 42
ASP AND XML 3 42
Adding Clickable Links to JQuery Data Items 24 58
ms sql and asp dates 5 44
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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