| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I redirect a form
I've got a problem and would be grateful for any help! I've
working on a form and would like to redirect users to diff. pages based on the option they select.If it helps any, The option's a session variable. Thanks |
|
#2
|
||||
|
||||
|
How about posting the code you've got so far?
MK |
|
#3
|
|||
|
|||
|
Here are the 2 functions I've got so far:
<% option Explicit if (session("Interested")= "Billing Questions")then Response.Redirect("billingcontact.asp") end if if (session("Interested") = "Need Instructions") or (session("Interested") = "Website Issues") or (session("Interested") = "Verification Issues/Questions") or (session("Interested") = "Account Questions") or (session("Interested") = "Employer Search Issues") or (session("Interested") = "Pricing") or (session("Interested") = "New Account Set Up") or (session("Interested") = "Credit Card Issues") or (session("Interested") = "Other") Then Response.Redirect("contact.asp") End If %> function direct() if (session("Interested")= "Billing Questions") { { document.theForm.action = "billingcontact.asp"; } else { document.theForm.action = "contact.asp" } return true; } Th 'onSubmit' event calls a function that validates the selection. I'd like to have both done at the same time i.e. the form validated and then the appropriate method chosen. Thanks a lot! Quote:
|
|
#4
|
||||
|
||||
|
Do you mean you want to get rid of the ASP server-side but and really on JavaScript that a) validates the FORM and b) changes the FORM's ACTION tag to point to the relevant page and SUBMITs the FORM?
MK |
|
#5
|
|||
|
|||
|
Yes, I'd like to have a javaScript function that calls the 'validation' function , and then changes the FORM's ACTION tag to point to the relevant page and SUBMITs the FORM.
Quote:
|
|
#6
|
||||
|
||||
|
Ok
You obviously know what you're trying to do with validation etc. I'd suggest you research the JavaScript SWITCH function to simplify your programming MK |
|
#7
|
|||
|
|||
|
Hi,
> I must apologize if my description of the problem was not clear. What I'm trying to with this form when it is submitted is : > 1) to have it validated - and that function's already been defined and works . > 2) to redirect the user to an apropriate form based on the choice that's been made. > So, I guess I need to create a function that redirects the user and also calls the other one. I've pasted a copy of the code and would be immensely grateful for your help! > thanks, > > > <% option Explicit > > > if (session("Interested")= "Billing Questions")then > Response.Redirect("billingcontact.asp") > end if > > if (session("Interested") = "Need Instructions") or (session("Interested") = "Website Issues") or (session("Interested") = "Verification Issues/Questions") or (session("Interested") = "Account Questions") or (session("Interested") = "Employer Search Issues") or (session("Interested") = "Pricing") or (session("Interested") = "New Account Set Up") or (session("Interested") = "Credit Card Issues") or (session("Interested") = "Other") Then > Response.Redirect("contact.asp") > End If > %> > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> > <html> > <head> > > <script language="javascript"> > <!-- > function direct() > if (session("Interested")= "Billing Questions") > { > { > Response.Redirect("billingcontact.asp"); > isThisValid > } > else > { > Response.Redirect("contact.asp") > } > return true; > } > > function isThisValid() > { > return validator(this) > } > --> > </script> > > > > </head> > > <body leftmargin="5" topmargin="5" marginwidth="0" marginheight="0"> > > > <table border="0" width="100%" cellpadding="0" cellspacing="0"> > <tr> > <td valign="top"><p>Choosing a question or subject from the list below is the the fastest way to get an answer. > In fact, we can usually answer your question instantly.<br><br> > Please pick a subject that relates to your question. > </p> > <form name="theForm" method="post" action="contact.asp" onsubmit="return validator(this)"> > <table width="100%" border="0" cellpadding="0" cellspacing="0"> > > > <tr><td width="40%" valign="top"><p> > <select name="Interested" size="1"> > <option<%If session("Interested")="Select Subject" then %> selected <%end if%>>Select Subject</option> > <option<%If session("Interested")="Pricing" then %> selected <%end if%>>Pricing</option> > <option<%If session("Interested")="Billing Question" then %> selected <%end if%>>Billing Question</option> > <option<%If session("Interested")="New Account Set Up" then %> selected <%end if%>>New Account Set Up</option> > <option<%If session("Interested")="Need Instructions" then %> selected <%end if%>>Need Instructions</option> > <option<%If session("Interested")="Website Issues" then %> selected <%end if%>>Website Issues</option> > <option<%If session("Interested")="Verification Issues/Questions" then %> selected <%end if%>>Verification Issues/Questions</option> > <option<%If session("Interested")="Account Questions" then %> selected <%end if%>>Account Questions</option> > <option<%If session("Interested")="Credit Card Questions" then %> selected <%end if%>>Credit Card Questions</option> > <option<%If session("Interested")="Employer Search Issues" then %> selected <%end if%>>Employer Search Issues</option> > <option<%If session("Interested")="Other" then %> selected <%end if%>>Other</option> > </select> > </p> > <p align="right"> > <input name="Submit" type="submit" value="Submit"> > </p> > <tr><td> </td><td width="18%"> </td> > <td width="42%"> </td> > </tr> > </table></form> > </td> > </tr> > </table> --> > </body> > </html> |
|
#8
|
||||
|
||||
|
This could be made simpler by adding validation markup to your input boxes and performing the validation on the page that you post to. For example:
Code:
<form method="post" action="val.asp"> <input type="text" name="Name_R"> Name (required)<br> <input type="text" name="Job_R"> Job description (required)<br> <input type="text" name="Phone" Phone number (optional) </form> Code:
<%
str_Errors = ""
For Each str_ItemFound In Request.Form
If InStr(str_ItemFound,"_") <> 0 Then
ary_Rules = Split(str_ItemFound,"_")
Select Case ary_Rules(1)
Case "R" ' Required field
If Request.Form(str_ItemFound) = "" Then
str_Errors = str_Errors & "The " & str_ItemFound & " field must be completed"
End If
End Select
End If
Next
If str_Errors <> "" Then
Response.Write("<script language=""JavaScript"">" & vbcrlf)
Response.Write("alert('Please correct the errors on your form:\n\n" & str_Errors & "');" & vbcrlf)
Response.Write("history.back(0);" & vbcrlf)
Response.Write("</script>" & vbcrlf)
Response.End
End If
%>
You can also use the Select to simplify your redirection: Code:
<%
Select Case Session("Interested")
Case "Need Instructions", "Website Issues", "Verification Issues/Question" ' etc.
str_Target = "contact.asp"
Case "Billing Questions"
str_Target = "billingcontact.asp"
Case Else
str_Target = "contact.asp"
End Select
Response.Redirect(str_Target)
%>
Last edited by selwonk : September 20th, 2004 at 05:01 PM. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > How do I redirect a form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|