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

how do you send user to a specfic page depending on form input?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a web form and would like to send the user to a specific page depending on what radio button they check.

For example if they say they like vanilla ice cream (variable = "vanilla") in the form, send them to page "A" once they hit the submit button. If they like chocolate (variable = "chocolate") , send them to page "B" once they hit submit.

Thanks, I really appreciate your help.

Ivan
 
This is a javascript question and this is a Java forum(a programming language). Perhaps next time you would like to post questions in the javascript forum?

Anyway take a look at this:-

<html>
<script language=&quot;javascript&quot;>
function redirect() {
if (document.form1.rd1[0].checked)
document.location.href=&quot; else if (document.form1.rd1[1].checked)
document.location.href=&quot; else if (document.form1.rd1[2].checked)
document.location.href=&quot;}
</script>
<body>
<form name=&quot;form1&quot;>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;vanilla&quot;>vanilla<br>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;chocolate&quot;>chocolate<br>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;strawberry&quot;>strawberry<br>
<input type=&quot;button&quot; value=&quot;Click&quot; onclick=&quot;redirect()&quot;>
</form>
</body>
</html>

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
yes its possible! Try this

=========================================================
RadioSubmitServlet.java
=========================================================

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class RadioSubmitServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

System.out.println(&quot;Inside doGet&quot;);
forward(request,response,&quot;RadioSubmit.html&quot;);

}


public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {

System.out.println(&quot;in dopost###########&quot;);
String variable = request.getParameter(&quot;rd1&quot;);
String page=&quot;&quot;;

System.out.println(&quot;variable = &quot;+variable);
if(variable==null){
page=&quot;NothingSelected.html&quot;;
}else if(variable.equals(&quot;vanilla&quot;)) {
page=&quot;A.html&quot;; //or A.jsp
}else if(variable.equals(&quot;chocolate&quot;)) {
page=&quot;B.html&quot;; //or B.jsp
}else if(variable.equals(&quot;strawberry&quot;)) {
page=&quot;C.html&quot;; //or C.jsp
}
forward(request,response,page);

}
public void forward (HttpServletRequest request, HttpServletResponse response, String pageName)throws ServletException, IOException {

System.out.println(&quot;Inside forward &quot;+pageName);
RequestDispatcher rd=null;
rd=getServletContext().getRequestDispatcher(&quot;/&quot;+pageName);
rd.forward(request,response);
}
}
=========================================================
RadioSubmit.html
=========================================================

<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;RadioSubmitServlet&quot;>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;vanilla&quot;>vanilla<br>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;chocolate&quot;>chocolate<br>
<input type=&quot;radio&quot; name=&quot;rd1&quot; value=&quot;strawberry&quot;>strawberry<br>
<input type=&quot;submit&quot; value=&quot;Click&quot; >
</form>
</body>
</html>
===========================================================

Hope this helps !

Regards
vikas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top