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

x
?
Solved

Values from request.form variables won't compare , but hard-coded ones will.

Posted on 2001-09-12
4
Medium Priority
?
201 Views
Last Modified: 2011-09-20
I have a piece of code which is baffling me.

I am trying to compare one variable, which has been loaded from a request.form object, with another one which has been loaded withing the ASP.  For testing, I am comparing the two and if they are equal I am writing a message to the screen.  

When I compare the two, I don't get any message, even though the values are equal when I write them out separately.  If I plug a value into the request variable and compare them, I get my message.

Why won't my comparisons work with imported data?

Here is some sample code:

The Form--
<form name=email method=post action="mailit.asp">
<input type=hidden name=secid value="match me">
</form>

The ASP--
<%
secid = request.form("secid")
secid1 = "match me"

if secid1 = secid then
   response.write "It matched!"
end if
%>
0
Comment
Question by:Barry62
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
jitganguly earned 400 total points
ID: 6477118
Try CStr function if it is character type or cint for numeric

<%
secid = request.form("secid")
secid1 = "match me"

if cstr(secid1) = cstr(secid) then
' OR if cint(secid1) = cint(secid) then
  response.write "It matched!"
end if
%
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6477123
Also you may want to use trim function Like

<%
secid = request.form("secid")
secid1 = "match me"

if cstr(Trim(secid1)) = cstr(Trim(secid)) then
 response.write "It matched!"
end if
%
0
 
LVL 8

Author Comment

by:Barry62
ID: 6477134
That was so easy!  Why didn't I think of that??

Thanks!
0
 
LVL 11

Expert Comment

by:Nitin Sontakke
ID: 6477136
For sure implementation please use both of the "jitganguly"'s suggestions. Use conversion functions to get correct values.

The trouble you are having is because all variables in all scripting languages are of data type variant and need explicit conversion before comparison.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

886 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