Solved

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

Posted on 2008-10-29
4
680 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
glad to help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now