Hello! I am a very green ASP user (but a fast learner), and am hoping someone can help me understand why my response.redirect is not redirecting.

Here is the situation:
I have a form on one page that, once a visitor clicks one of 2 buttons, sends visitors to "decision.asp". The "decision.asp" file is purely to re-direct the visitor to one of 2 pages, depending on which button they clicked on the form. Except, all it does is show a blank white page.

Here is the code:

<%	

  Response.Buffer = True

  Whichbuttonclicked = "?"

  if Request.Form("Form1") = "ButtonA" then
    Whichbuttonclicked = "A"
  elseif Request.Form("Form1") = "ButtonB" then
    Whichbuttonclicked = "B"
  end if


  Select Case Whichbuttonclicked
    Case "A"
      Response.Redirect "buttonA.asp"
    Case "B"
      Response.Redirect "buttonB.asp"
  End Select

If you need additional information, please let me know. I really appreciate any guidance anyone can provide!!

Thank you.

Can you post your form html? Thanks.

There is probably just a disconnect between the form item names and your form processor code.

Can you post your form html? Thanks.

There is probably just a disconnect between the form item names and your form processor code.

Here's the HTML for my form ("decision.asp", referenced below, is the name of the file that contains the coding previously listed):

<form name="Form1" method="POST" action="decision.asp" onSubmit="return false;">
<input type="hidden" name="hdn_proj_id" value="(Project name)">
<p><font color="<% = pub_GLOBAL_ColorBody %>" face="<% = pub_GLOBAL_FontBodyText %>"><b>Your name:</b><br>
<input type="text" name="Part_name" size="50"><i><small>required</i></small></font></p>
<p><input type="submit" name="Buttons" value="ButtonA" onClick="Validate(this.form);"></p>
<p><input type="submit" name="Buttons" value="ButtonB" onClick="Validate(this.form);"></p>
</form>

Please let me know if there's any other information you need... Thanks so much for any help you can provide!

Ok, the answer lies in your use of request.form, which is incorrect.

You are requesting the value of your form. You must request the value of a form item, not the form itself.

So you have <form name="Form1" method="POST" action="decision.asp"> and Request.Form("Form1") So you can see that your requesting the value of the form. Instead, you should be requesting the value of your buttons inputs, like so: Request.Form("Buttons") So, make that change in your decision.asp script and it will work. I have successfully ran it here and landed on buttonA.asp and buttonB.asp.

I would also recommend dropping the FONT tag and using valid xHTML 1.0 Transitional or Strict.

Cheers, please mark as solved once you get your code working!

Thank you for your feedback.

Unfortunately, I just realized that, when I "anonymized" the code, I made a mistake. In the code I've been testing, it actually is listed as Request.form("Buttons"), yet I still am brought to the page decision.asp, and it stays there with a just white screen.

Do you have any other thoughts as to what might be the issue? Could there be server settings or something along those lines that I should check/verify?

Again, I really appreciate your help. Thank you!

Try doing a response.write(Request.Form("buttons")) on your decision.asp page and let me know what the value is when you click on either button.

I don't see anything - the page is still just white. Awhile ago, I did put "Button: <%=Decision%>" on the page (with the <HTML> and <BODY> tags before the script began, and the closing for same tags after this line) and it returned "Button: ?".

Here is the code as it actually is (not anonymized). Maybe there's something here that I'm missing??

Thank you!

Code:

<%	

  Response.Buffer = True

  Decision = "?"

  if Request.Form("ConsentDecline") = "Consent" then
    Decision = "Consent"
  elseif Request.Form("ConsentDecline") = "Decline" then
    Decision = "Decline"
  end if




  Select Case Decision
    Case "Consent"
      Response.Redirect "index-2.asp"
    Case "Decline"
      Response.Redirect "decline.asp"
  End Select




%>

And here is the form code, non-anonymized:

<form name="Rater_Consent" method="POST" action="decision.asp" onSubmit="return false;">
      <input type="hidden" name="hdn_proj_id" value="(Proj name)">
      <p><font color="<% = pub_GLOBAL_ColorBody %>" face="<% = pub_GLOBAL_FontBodyText %>"><b>Name of the person you are consenting/declining to describe:</b><br>
         <input type="text" name="Part_name" size="50"><i><small>required</i></small></font></p>
      <p><input type="submit" name="ConsentDecline" value="Consent" onClick="Validate(this.form);"></p>
      <p><input type="submit" name="ConsentDecline" value="Decline" onClick="Validate(this.form);"></p>
    </form>

As a note, you should clean up your code a bit; when adding HTML tags you should follow the rule of thumb, which means when you have an italic tag surrounding text make immediate close on other side, never have tags separated with other tags:

<i> <small> required</i> </small>

Should be

<i> <small> required </small></i>

or reverse - small tag first then italic.

Back to your question, it is not good practice to have 2 submit buttons for 1 form_object; rather use regular buttons with a JS document.location or a drop down box for your selections that have their own unique value.

EXAMPLE:

<form name="Rater_Consent" action="decision.asp" method="POST">
<input type="hidden" name="hdn_proj_id" value="(Proj name)">
<input type="text" name="Part_name" size="50">
<select name="ConsentDecline" onchange="this.form.submit()">
<option value="A">Consent</option>
<option value="B">Decline</option>
</select>
</form>

EXAMPLE ALTERNATIVE:

<form name="Rater_Consent" action="decision.asp" method="POST">
<input type="hidden" name="hdn_proj_id" value="(Proj name)">
<input type="text" name="Part_name" size="50">
Consent: <input type="radio" name="ConsentDecline" value="A">
Decline: <input type="radio" name="ConsentDecline" value="B">
<input type="submit" name="cmdSubmit" value="Commit">

On receiving page, decision.asp you will be able to decipher which value is used and then determine where to send it. However, unless you are using more than 2 options, make your code simple to use and read and do not use a case select statement.

DECISION PAGE:

dim partName, projName, decision

projName = Request.Form("hdn_proj_id")
partName = Request.Form("Part_Name")
decision = Request.Form("ConsentDecline")

if decision = "A" then
  Response.Redirect("pagname_a.asp")
else
  Response.Redirect("pagname_b.asp")
end if

I hope this information helps you decide what to do when passing your information to and from ASP pages. Furthermore, if you want to validate a form, validate the type of text you are receiving, do not worry about validating form_object_buttons. I can help you with the validation when you need to.

Back to your question, it is not good practice to have 2 submit buttons for 1 form_object; rather use regular buttons with a JS document.location or a drop down box for your selections that have their own unique value.

If this is a public site, forms and javascript are not a really good idea in terms of accessibility. Industry best practice is actually to have all forms working _without_ javascript, and then you can use javascript to override that functionality. This way, the website works with both javascript on and off, which is good for the visually impaired using screen readers, mobile phones (I've seen several blackberrys with JS turned off by default...) etc.

TomBCullen is correct in stating that two submit buttons shouldn't be used. If you wish to have one button as a default, then set that as a type="submit" other wise set both to just type="button".

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.