Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if test (seemingly) taking wrong branch

Status
Not open for further replies.

toddj1

Programmer
Nov 6, 2002
3
US
Hello
I am running a very simple javascript as an ASP on a windows 2000 server! (KEYNOTE javascript on an ASP windows 2000 server!!!!) Its my understanding as long as you start your script with &quot;<%@ language=&quot;javascript&quot;%>&quot; it will work! Apparently it does (well almost) because without it you get all kinds of syntax errors.

In this code I have a form with 2 fields f1 & f2 plus a submit button. Pressing the submit button runs the same script to process f1 & f2.

The problem is an if test I have that compares f1 & f2. It reads &quot;if (f1 != f2) { ....&quot;

No matter what values are put in f1 & f2 it always enters the &quot;then part of the if&quot; even if f1 & f2 are equal (say 1 & 1)! Weird and probably a DUH but I just can't see it!

As a side test I changed the if to a less than (<) or greater than (>) test and entered numbers &quot;accordingly&quot;! The if test worked in that state! Therefore the &quot;if test&quot; is apparently working and so is javascript just not for != or == constructs! (yup tried == too!)

Again you must have access to a windows 2000 ASP engine to test this! Just so you know, This has already stumpped another forum and my Hosting service! In fact there words were &quot;The code appears to be fine and several of us pulled our hair out about it earlier today and still couldn`t see it.&quot; Personally I think its a microsoft problem which isnt such a good problem for me! Anyway Thanx in advance!



Here is ASP code.
<%@ language=&quot;javascript&quot;%>
<%
// Are we processing the form else posting the form!
if (Request(&quot;Func&quot;) == &quot;Process Form&quot;) {
Response.Write(&quot;Processing Form&quot;);
f1 = Request(&quot;f1&quot;);
f2 = Request(&quot;f2&quot;);
Response.Write(&quot;f1=(&quot;+f1+&quot;)f2=(&quot;+f2+&quot;)&quot;);
if (f1 != f2){
Response.Write(&quot;Sorry, f1 & f2 are not identical!&quot;);
Response.Write(&quot;Notice the print above. If they are identical, then why doesn't this work? &quot;);
}
Response.Write(&quot;Use the Back button to try again&quot;);
Response.End();

}
else {
%>
<html>
<head>
<title>Form Tester</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot;>

<form method=&quot;post&quot; action=&quot;<%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;)%>&quot; name=&quot;theform&quot;>
f1: <input type=&quot;text&quot; name=&quot;f1&quot;>
f2: <input type=&quot;text&quot; name=&quot;f2&quot;>
<input type=&quot;submit&quot; name=&quot;Func&quot; value=&quot;Process Form&quot;>
</form>

</body>
</html>
<%
}
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top