Hi all,

I have a simple problem but a major 1 for me now...
i need to pass the selected value of radio button from 1 jsp to another jsp i.e when user selects a radio button option and then clicks on the submit button then the selected value should b passed to another jsp and should b able to display it....
plz help me out ......
ne sample code will b highly beneficial......:sad:

Hi all,

I have a simple problem but a major 1 for me now...
i need to pass the selected value of radio button from 1 jsp to another jsp i.e when user selects a radio button option and then clicks on the submit button then the selected value should b passed to another jsp and should b able to display it....
plz help me out ......
ne sample code will b highly beneficial......:sad:

Hai Sandeep,

I guess the following code is the answer for your question.

I have two jsp files. one is test1.jsp and another is test2.jsp.
i have radio buttons in test1.jsp file and i am trying to print the valur of radio button in test2.jsp.

test1.jsp

<[EMAIL="%@page"]%@page[/EMAIL] import = "java.io.*, java.util.*,java.text.*"%>
<html>
<head>
<script language="javascript1.1">
function validate()
{
f=document.forms[0];
alert("validate Starts");
for(var i=0;i<5;i++) {
if(f.radiobutton.checked) {
f.hide.value=f.radiobutton.value;
alert("value stored");
}
}
f.hiddenField.value="one";
return;
}
</script>
<title>Test</title>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name="form1" method="post" action="test2.jsp">
<p>
<label>
<input name="radiobutton" type="radio" value="one">
One
</label>
<br>
<label>
<input name="radiobutton" type="radio" value="two">
Two
</label>
<br>
<label>
<input name="radiobutton" type="radio" value="three">
Three</label>
<br>
<label>
<input name="radiobutton" type="radio" value="four">
Four
</label>
<br>
<label>
<input name="radiobutton" type="radio" value="five">
Five
</label>
<br>
</p>
<p>
<input name="submit" type="submit" id="submit" onclick="validate()" value="Submit">
</p>
<p>
<input name="hide" type="hidden" id="hide">
<input type="hidden" name="hiddenField">
</p>
</form>
<p>&nbsp;</p>
</body>
</html>


Test2.jsp

<[EMAIL="%@page"]%@page[/EMAIL] import="java.sql.*,java.util.*"%>
<%@ page import ="java.util.regex.Pattern, common.Util"%>
<%
String hide=null;
String hide1=null;
if(request.getParameter("hide")!=null)
hide=request.getParameter("hide");
if(request.getParameter("hiddenField")!=null)
hide1=request.getParameter("hiddenField");
%>
<html>
<head>
<title>Test2</title>
</head>
<body>
<form name="form1" method="post">
<input type="text" name="textfield" value="<%=hide%>">
<input type="text" name="textfield" value="<%=hide1%>">
</form>
</body>
</html>


hope so you understand.
Bye...

This article has been dead for over six months. Start a new discussion instead.