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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP/VBS Multiple If..Then's.. Basic Question 1

Status
Not open for further replies.

DSect

Programmer
Sep 3, 2001
191
US
Hello.

I am doing some form validation and I am having a problem.

I want the code to check for an empty text box and if the box is empty, then display a message above it in the form. Only files that were left blank will have error messages above them.

I am able to do it for ONE field, but if I sting multiple if..then statements together, it does not act like I would want. Rather, it steps through and does not flag all the blank fields..

I am very newbie, but I have made some big strides when it comes to syntax.. Unfortunately, I am unable to find a smart way to do this error thing I am trying to do.

The code shows a working example with The "FirstName" field acting how I'd want it. That's as far as I can get.. I can't seem to get it to check all the variables for NULL ("") and then report the status by modifying the Error String variables I made (strE1, strE2, etc..).

Any and all help is appreciated.. Thanks!


Here's my code for it:

' Create Variables for the form elements
Dim strFirstName, strLastname, strEMailAddress
Dim bitSubscribe, strUsername, strPassword

Dim strE1, strE2, strE3, strE4, strE5, strE6 ' Error Strings for each field

' Assign form values to the variables
strFirstName= Request.Form("FirstName")
strLastname= Request.Form("LastName")
strEMailAddress= Request.Form("EMailAddress")
bitSubscribe= Request.Form("btnSubscribe")
strUsername= Request.Form("Username")
strPassword= Request.Form("Password")

If strFirstName = "" then
strE1 = "First name is required"
Else
strE1 =""
End if
%>

I then use Response.Write to print the error message in the form above the textbox. If the error variable is blank (strE1="") then no message shows up.

I just can't do it for all the variables.

Yet..
 
strerror = ""

If len(strFirstName) = 0 or IsNull(strFirstName) then strerror = strerror & "ErrorFirstName"
If len(strLastname) = 0 or IsNull(strLastname) then strerror = strerror & "ErrorLastname"
and so on for all textboxes you have
and then finally you display the whole string:
Those are the errors from the page:<% response.write strerror%>

Or you could do it more elegant making a validation on the client side in JavaScript

Hope I understood you and my message helped you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top