So I'm coding a form in html and ASP and so far I have it working perfectly in terms of going from one page of the form to the next and shooting off an email at the end as verification of the form input.

What I've just inserted into the code now are some new form elements, namely a password and confirm password (this is for a member registration form).

What I want is for the page to proceed to the next part of the form if the password is the same as the confirm password, and to blast an error if the password values are not the same.

The select case statement that involves moving from one page to another (which worked until I inserted the bolded items) is this

Select Case Request.Form("navigate")
	Case "< Back"
		intCurrentPage = intPreviousPage - 1
	Case "Next >"
		[B]If Request.Form("cWP") = Request.Form("cWPconfirm") Then[/B]
		intCurrentPage = intPreviousPage + 1
		[B]Else
		AbortMessage = "Password mismatch, please re-enter and reconfirm password"
		
		End If[/B]
	Case Else
		' Either it's our first run of the page and we're on page 1 or
		' the form is complete and pages are unimportant because we're
		' about to process our data!
		intCurrentPage = 1
End Select

I want to break out of the select statement once I reach the password mismatch, but the term "break" does nothing in ASP, so I'm wondering what is it's equivalent, or if there is even a way in the first place to exit from a select case statement.

Thanks so much beforehand for any and all advice. I hope nothing that I've mentioned so far is unclear or vague. Let me know if it is and I will try to clarify.

-LP

Hello,

Perhaps try a string Comparison to see if the values are the same, and I am not sure what the brackets before your Back case and after your Next case are for. Also if you are moving to a different page if the passwords match you might want to add Response.Redirect "Different_Page.asp" in your if statment to exit the case and page. Depending on the server you are on you may also want to do a conversion of the two form elements you are comparing "CStr"

I hope I understood what it is you are trying to do.

Select Case Request.Form("navigate")
   Case "Back"
      intCurrentPage = intPreviousPage - 1
   Case "Next"
      If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then
         intCurrentPage = intPreviousPage + 1
         Response.Redirect "Different_Page.asp"
      Else
         AbortMessage = "Password mismatch, please re-enter and reconfirm password"
      End If
   Case Else
      intCurrentPage = 1
   End Select

Hi CTS,

Thank you for the advice on the structure of the code. A couple of clarifications for you:

1. I'm staying within the same page and using select case statements to change the form based on the "current page" that you are on. Basically it's trying to mimic a multi-page form without ever leaving the first page.

2. The carats/brackets after Next and Back are just the values for the submit buttons on the bottom of the form. Aka Next > and < Back. They both have the name "navigate" and so it's basically trying to figure out which of the 2 buttons was pushed and what to do based on what button was pushed.

I realized after some more exhaustive research that there is no break out of a select case statement, except to do

For i = 0 to 1
Select Case Request.Form("Navigate")
           Case "< Back"
                   intCurrentPage = intPreviousPage - 1
           Case "Next >"
                   If Request.Form("cPW") = Request.Form("cPWconfirm) Then
                      intCurrentPage = intPreviousPage + 1
                   Else
                      AbortMessage = "Password Mismatch, please try again"
                   Exit For
                   End If
...

I have changed my code now to use StrComp to compare the 2 passwords, as it seems more clean and efficient.

Hello LurkerPatrol,

Ok now I think I have a better idea of what you are trying to do.

First thing, add a hidden value to your initial form.

Response.Write "<input type='hidden' name='ispostback' value='1'>"
Response.Write "<input type='navigate' value='< Back' name='Back'>"
Response.Write "<input type='navigate' value='Next >' name='Next'>"

Then at the top of your page under your dim statments check for the hidden value. If the value is null it will fall through and run a sub that dispays the initial page. if the hidden value is true it will run the nested if statments.

First = len(Request.Form ("IsPostBack")) < 1
If First Then
  If Request.Form("navigate") = "Next" Then
     If StrComp(Request.Form("cWP"),Request.Form("cWPconfirm"))=0 Then
        Call SComplete
     Else
        AbortMessage = "Password mismatch"
        Call SLoginForm
     End If
  Else
     Call SBackForm
  End if
Else
   Call SForm
End if

I am not sure of the structure of your page but if the comparison for password is true the code will call a sub (SComplete) that displays the final result. If there is an error in the password it will call a sub (SLoginform) that will show the password form and allow the AbortMessage to be shown. Now if Request.Form("navigate") does not = "Next" it will call the sub (SBackform) that the user requested by hitting the "Back" button. As I said I am not sure on your page setup the back button may bring up the same form as the password form in which case you would only need to call the one sub (SLoginForm) for each instance.

I hope this helps out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.