Need help with multiple buttons on single form...

Hi,

I have a webform that the user can click one of two buttons at the bottom.  Both buttons save the changes on the form to a MySQL Database, but the "Previous" button returns to one form and the "Next" button goes to a different form.

My <form> statement points to a single .asp script that saves the data.  What I want is for that script to somehow tell which button the user clicked and then redirect to the appropriate form.

What would the code for that redirect based upon the button click look like?
LVL 5
MitchellVIIAsked:
Who is Participating?
 
Carl TawnSystems and Integration DeveloperCommented:
Just to expand slightly:
'// assuming you have a form defined something like this
<form method="post">

   <input type="submit" name="PrevButton" value="Previous" /><br />
   <input type="submit" name="NextButton" value="Next" /><br />

</form>


'// you could then use the following at the server-side
<%
If Request.Form("PrevButton") <> "" then
    Response.Redirect("http://www.myWebsite.biz/forms/Previous_Form.asp?ProspectID=" & Upload.Form("ProspectID")) 
ElseIf Request.Form("NextButton") <> "" then
    Response.Redirect("http://www.myWebsite.biz/forms/Next_Form.asp?ProspectID=" & Upload.Form("ProspectID")) 
End if
%>

Open in new window

0
 
Gurvinder Pal SinghCommented:
change the document.form[0].action value to point it to a different action on server side
0
 
MitchellVIIAuthor Commented:
Sorry, i'm a noob.

Let's say my current .asp script looks like this:

<%Response.Redirect("http://www.myWebsite.biz/forms/DocEPW_IT_Group.asp?ProspectID=" &  Upload.Form("ProspectID"))
%>

How would I write the code so that it redirected based upon which button was clicked?  Sorta like:

If user clicks "Previous" button, then
    Response.Redirect("http://www.myWebsite.biz/forms/Previous_Form.asp?ProspectID=" & Upload.Form("ProspectID"))
ElseIf user clicks "Next" button, then
    Response.Redirect("http://www.myWebsite.biz/forms/Next_Form.asp?ProspectID=" & Upload.Form("ProspectID"))
End if

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Carl TawnSystems and Integration DeveloperCommented:
Or you can check Request.Form at the server-side. There should be an entry in there that matches the button that submitted the form.
0
 
MitchellVIIAuthor Commented:
Guys walk me through it, ur talking above my head here :)
0
 
Carl TawnSystems and Integration DeveloperCommented:
You could use:
If Request.Form("NameOfPrevButton") <> "" then
    Response.Redirect("http://www.myWebsite.biz/forms/Previous_Form.asp?ProspectID=" & Upload.Form("ProspectID")) 
ElseIf Request.Form("NameOfNextButton") <> "" then
    Response.Redirect("http://www.myWebsite.biz/forms/Next_Form.asp?ProspectID=" & Upload.Form("ProspectID")) 
End if

Open in new window

0
 
sybeCommented:
Give the both submit buttons the same name. In the code below they are supposed to be named "submitbutton"
<%
If Request.Form("submitbutton") = "Next" Then
   Response.Redirect("Next.asp")
Else
   Response.Redirect("Previous.asp")
End If
%>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.