Solved

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

Posted on 2008-10-29
4
682 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

20 Experts available now in Live!

Get 1:1 Help Now