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

Redirecting a page...

Status
Not open for further replies.

mangocinn

Programmer
Jul 26, 2001
66
US
Please help...

Question: Is it possible to redirect a page which contains a form with the action set to the same page.

For example:
SamePage.asp

<%
If Request.Form (&quot;Try&quot;) = &quot;Try&quot; then
Response.Redirect &quot;NewPage.asp&quot;
else%>
<form method=&quot;POST&quot; action=&quot;SamePage.asp&quot;>
<INPUT type=&quot;text&quot; id=text1 name=Message>

<INPUT type=&quot;submit&quot; value=&quot;Try&quot; name=Try>
</form>
<%end if%>

I simplified my prob to the above code. In my real situation, I need to regenerate the page because the data in one of my drop downs depends on the selection of another drop down. However, after the user enters all the info and hits submit...I would like to process the form data in a different page. Is this possible or do I have to process the form in the same page after submit button is clicked?

Please Help....Thanks...:)
 
Much easier to just have the page submit itself using the onChange() method. So if list box B depends on list box A then set the page to submit onChange() of list box A. Then you can repopulate the Form and popluate list box B with valid values. Wushutwist
 
Yes it is possible to return to the same page after submitting a form, build the page again with a new input field that has a select field with a menu based on the submitted data, submit again returning to the same page but re-direct to a new page to process the data in the form.

Instead of testing the value of the submit field as in your example, test a hidden field. When you first build the page place a value in the hidden field to indicate that that the form has been submitted. The first time the script is run, this field will not exist, the second time it will exist, so you can test it to determine whether to build the form with a new field or to re-direct to another page.

Code:
If IsEmpty( Request.form(&quot;return_visit_expected&quot;) ) Then 
   Response.write &quot;<input type='hidden' name='return_visit_expected' value='yes'>&quot;
   Response.write &quot;code to build the page the first time.&quot;

Else If Request.form(&quot;return_visit_expected&quot;) = &quot;yes&quot; Then
   Response.write  &quot;<input type='hidden' name='return_visit_expected' value='no'>&quot;
   Response.write &quot;code to build the page with the variable select field that depends on the submitted form data.&quot;

Else
   Response.Redirect &quot;NewPage.asp&quot;

End If
 
Thanks for the advice.

It seems that my problem was misunderstood. Sorry bout that...let me clarify
I have a form which includes two select boxes. One of those, depend on the other. So, I am using the onChange event to submit the form when user changes select A. Since Select B depends on Select A, Select A is required. However, select B can be left empty. Since I am using the onchange event I am having the form's action set to regenerate the same page. This portion of it works fine.
When the user submits, I would like to go a different page.
Since select B can be left empty, the only way I know if they are ready to go further is to check if they hit submit (Try).
Maybe this will help...


This is SamePage.asp
<%
If Request.Form (&quot;Try&quot;) = &quot;Try&quot; then
Response.Redirect &quot;NewPage.asp&quot;
else%>
<form method=&quot;POST&quot; action=&quot;SamePage.asp&quot;>
<select name=&quot;selectA&quot; onChange=submit();>
<option> option1 </option>
</select>
<%
If Request.form (&quot;selectA&quot;) <> &quot;&quot; then%>
<select name=&quot;selectB&quot;>
<option> type1 </option>
<%end if%>

<INPUT type=&quot;submit&quot; value=&quot;Try&quot; name=Try>
</form>
<%end if%>

The response.redirect causes an error when used this way. Is there any other way to accomplish this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top