Radio Button Problem in jsp.
I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button for each row as i got data from the database using iterator tag,but when i select any row the it is going to bind the last iterated value, please can anyone clear my doubt.and disabled all previous values.
myjsp is like that
<%@ taglib prefix="display" uri="http://displaytag.sf.net/el"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@page import="java.util.*"%>
<%@page import="java.util.Iterator"%>
<%@page import="inc.eis.info.api.TestQuestion"%>
<h3 align="center">List of Questions</h3>
<table width="530" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="530" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td align="left" valign="top" style="padding:6px;" class="borderred">
<table border="0" align="left" cellpadding="0" cellspacing="0" width="95%">
<s:form theme="simple" name="startTestForm" >
<!-- <hr width="100%" bordercolor="red"> -->
<table>
<%! HashMap s=null; %>
<%
List qs=(List)request.getAttribute("list");
Iterator questions= qs.iterator();
for(int i=1;i<2;i++){
TestQuestion tqDet=(TestQuestion)qs.get(i);
s=new HashMap();
s.put(i,tqDet);
%>
<tr>
<td colspan="2" align="left"><b class="textboldblack"><%out.println(i);%><%out.println(tqDet.getQuestions());%></b></td></tr>
<tr><td width="22%"align="left"><b class="textboldblack"><input type="radio" name="test" id="A" ><%out.println(tqDet.getAns_a());%></b></td></tr>
<tr><td width="22%"align="left"><b class="textboldblack"><input type="radio" name="test" id="B"><%out.println(tqDet.getAns_b());%></b></td></tr>
<tr><td width="22%"align="left"><b class="textboldblack"><input type="radio" name="test" id="C"><%out.println(tqDet.getAns_c());%></b></td></tr>
<tr><td width="22%"align="left"><b class="textboldblack"><input type="radio" name="test" id="D"><%out.println(tqDet.getAns_d());%></b></td></tr>
<%
}
%>
<tr><td colspan="2" align="center"><input type="submit" value="Next" onclick="callAction()"></td>
</tr>
</table>
</s:form>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%-- <s:hidden name="" id="radioButtons[x].id" value="seloption"></s:hidden> --%>
<script language="javascript">
function callAction(){
alert("hi ");
var radioButtons = document.getElementsByName("test");
for (var x = 0; x < radioButtons.length; x ++) {
if (radioButtons[x].checked) {
var option=radioButtons[x].id;
// var seloption=document.getElementById("radioButtons[x].id").value;
alert("your selected answer is:: " +option);
document.startTestForm.action="radioSave.action?option="+option;
document.startTestForm.submit();
//alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
}
}
}
</script>
View Answers
October 19, 2011 at 4:31 PM
We are providing you a simple application.
Create table test(ques,op1,op2,op3,op4,ans) and answers(id,ans). Then try the following code:
1)form.jsp:
<%@page import="java.sql.*"%>
<html>
<form method="post" action="result.jsp">
<table>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("Select * from test");
int i=1;
while(rs.next()){
%>
<tr><td><%=i%></td><td><%=rs.getString("ques")%></td><td><input type="radio" value="<%=rs.getString("op1")%>" name="radio<%=i%>"/><%=rs.getString("op1")%></td><td><input type="radio" value="<%=rs.getString("op2")%>" name="radio<%=i%>"/><%=rs.getString("op2")%></td><td><input type="radio" value="<%=rs.getString("op3")%>" name="radio<%=i%>"/><%=rs.getString("op3")%></td><td><input type="radio" value="<%=rs.getString("op4")%>" name="radio<%=i%>"/><%=rs.getString("op4")%></td></tr>
<%
i++;
}
%>
<tr><td><input type="submit" value="submit"></td></tr>
</table>
</form>
</html>
2)result.jsp:
<%@page import="java.sql.*"%>
<%
String st[]=new String[10];
for(int i=0;i<st.length;i++){
int j=i+1;
st[i]=request.getParameter("radio"+j);
System.out.println(st[i]);
}
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery("Select ans from answers");
String ans="";
while(rs.next()){
ans+=rs.getString("ans")+" ";
}
int count=0;
String answers[]=ans.split(" ");
for(int i=0;i<answers.length;i++){
if(st[i].equals(answers[i])){
count++;
}
}
out.println("Your "+count+" answers are correct");
%>
October 19, 2011 at 5:26 PM
thanks deepak . i got the soution.
October 19, 2011 at 6:17 PM
Hi deepak,
how to get the multiple selected radio button values from jsp to action using javascript.
Ads
Related Tutorials/Questions & Answers:
Radio Button Problem in jsp.
Radio Button Problem in
jsp. I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a
radio button...
radio button values from
jsp to action using javascript
Struts 2 radio button value problem
Struts 2
radio button value problem When I use s:
radio tag in struts...('radioButtonName').value.(Note :- I'm getting proper value in java from
jsp)
It always gives first
radio option's value as the value for any option selected.
Ex
Advertisements
radio button
radio button On selecting a
radio button, it should open a aspx page
How to use radio button in jsp page
How to use
radio button in
jsp page
 ...
button in
jsp code and display a message in another
jsp page according... according to student data then click submit
button that will call another
jsp page
java radio button and exception
java
radio button and exception Dear Sir/Madam,
I have
problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1
radio button can be selected, but somehow 2 can be selected the same time. Also, I
RADIO FROM JSP TO ACTION.
RADIO FROM
JSP TO ACTION. Hi frds,
how to get the selected multiple
radio button values from
jsp to action
Query on radio button
Query on
radio button I am having a multiple row in
jsp page.They are dynamically coming.
For each row there is one
radio button. I want to select... are displayed in the
jsp page using bean tag.
Please provide me some suggestion
validation of radio button
validation of
radio button There are 3
radio button as A,B,W. there are another
radio as 1,2,3.if we select W in first
radio button then should select 2nd one(1,2,3).if we select A or B not need select any one from 1,2,3
Struts 2 Radio Button
radio buttons and
I am using Struts2 tag.I want first rado
button to be selected by default.But when i select the second
radio button and hit on search
button i want to retain the selection of that second
radio button on search list
Radio button Validation
Radio button Validation Hi..
How to validate
radio button in java?if the
radio button is not selected an error message should be given...
Please...()==false)){
JOptionPane.showMessageDialog(null,"Please select
radio button
iPhone Radio Button Example
iPhone
Radio Button Example Can you please suggest me how to create
Radio button in my iPhone application. Actually, in my application i have two... click on that
button it get selected and by default it should display unselected
dependent radio button
of the
Radio Button is to select only one option at a time. So you don't need...dependent
radio button Hi. I have 4
radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected
passing value of radio button
passing value of
radio button hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two
radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
access into radio button
access into
radio button access the four fields of database called access,access file and stored in
radio button.please help
Drop down and radio button value on edit action
the value from dropdown and
radio button..
But the
problem goes with edit action...Drop down and
radio button value on edit action HI,
I have... for text boxes..bt select default value for dropdown and
radio button...How do
check radio button on retrieving the value from database.
check
radio button on retrieving the value from database. HI
i am... database and according to that i want to check the
cash cheque
radio button... information from database the i want to show
cash
radio button checked.How can i do
Dojo Radio Button
Dojo
Radio Button
 .... For creating
radio button you need "dijit.form.CheckBox".
The
radio button do some action on press.
Try Online:
Radio
Button
The RadioButton class
Radio Button in HTML
Radio Button in HTML is a type of input form that allows a user to select one
button from a group of
button. When a user clicks on a
radio button, it becomes...; specifies the component type is
radio button or not. If a programmer use type="
radio
Radio Button in Java
Radio Button in Java
Radio Button is a circular
button on web page that can be selected by the user.
The AWT Widget used to create a
radio button is Checkbox
radio button value on edit action
...
Problem 'm facing is on edit action 'm not retrieving
radio button value..i have used if else logic..Bt its not working...My edit.jsp code is:-
Radio button name...
radio button value on edit action This is my edit.jsp code...In my
Swing Problem on submission of button
Swing
Problem on submission of button How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of
button in swing
Get radio button value after submiting page
, the value of the selected
radio button get displayed in that
jsp page.
<... the following link:
http://www.roseindia.net/
jsp/
radio-
button-jsp.shtml...Get
radio button value after submiting page
Radio buttons
jsp problem
jsp problem Hi every one plz give me answer for below question ASAP
I created one
JSP(used pre defined javascript in
jsp to get rtf format... enterd data when click on preview
button it as to seperate data for every 42 lines
pass radio button values to next page
pass
radio button values to next page how to pass selected
radio button values which coming from mysql database to next page using php. Please show me with examples
Problem in jsp.
Problem in
jsp. hello friends, I have a
problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/
jsp/insertdata.jsp">
<table>
<