11

How can I check if the user has input a null or empty string in classic-asp? Right now I am have this code.

If Request.Form("productId") == "" Then
'my code here
End If

But its not working.

Malachi
  • 3,205
  • 4
  • 29
  • 46
itsaboutcode
  • 24,525
  • 45
  • 110
  • 156

3 Answers3

10

Classic ASP/VBScript uses one = to check for equality, not two. Another thing you may want to try is

If Request.Form("productid") = "" Then
   Code here
End If
Anthony Pegram
  • 123,721
  • 27
  • 225
  • 246
  • Thanks look like its working. If you can give little more help. What is operator for != in classic asp? – itsaboutcode May 15 '10 at 02:27
  • 4
    Except that Request.Form("productid") will NEVER be an object, so the test for "Is Nothing" can NEVER be true. If there is no value passed, simply testing against an empty string is sufficient. – BradBrening May 15 '10 at 13:00
  • @Brad, Thanks for the info, it has been a while since I've done classic ASP beyond trivial maintenance. Removed that check from answer. – Anthony Pegram May 15 '10 at 14:45
1

It is a mess. Here's what I have found ...

(1) To look for existence in the QS, use if IsEmpty(x)=false (ie, URL?x)

(2) To look for a value in the QS, look for if x <> "" (ie, URL?x=anything)

Good luck!

den232
  • 682
  • 6
  • 14
0
If IsEmpty(Request.Form("inputPhoneNo")) = False Then
    response.Write"<script language=javaScript>alert('Blank Phone Number');</script>"
    response.Write"<script language=javascript>history.back()</script>"
Else

End If
Nick is tired
  • 6,860
  • 20
  • 39
  • 51