Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In this code all the radiobuttons are getting checked. I want any one radiobutton to be checked in all rows.
please do anybody help me.

XML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>


<head>
<title>HTML Tables</title>
</head>
<body>

<%@ page import="java.sql.*"%>

<table bgcolor="lightgray" border="5" width="60%" cellpadding="5" cellspacing="0.5" color="blue" >
<tr>

<th colspan ="3" bgcolor="#999999"><br>


<div align="Center" > <font face="verdana" size="5" color="white"> ATTENDANCE </font>
</div>
</th>
</tr>

<tr>
<td width="14%"><h3>Register No</td>
<td><h3> Student Name</td>
<td><h3> Attendance</td>
</tr>
<tr>
<td> 1 </td>
<td> <input type="radio" >Present <input type="radio">Absent
<tr>
<td>2</td>
<td> <input type="radio" >Present <input type="radio">Absent
</tr>



<%
Connection dbcon=null;

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        dbcon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
        Statement stmt=dbcon.createStatement();
        ResultSet rst=null;

rst=stmt.executeQuery("select * from studenttables");
while(rst.next())
{%>
<tr>

<td><%=rst.getString("name")%></td>

</tr>
<tr>
<td><%=rst.getString("name")%></td>
</tr>

<tr>
<td><%=1%></td>
<td><%=rst.getString("name")%></td>
<td><input type="radio" >Present <input type="radio">Absent
</tr>

<% } %>


</table>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>
Posted

Replace your radio button code with the following,
HTML
<input type="radio" name="presenceFor1" />
Give unique name for each row, and same name for each td in row for radio buttons.
Read W3C[^] for more idea.

-KR
 
Share this answer
 
v3
You can simply give the same name to the respective radio groups to achieve this like:

HTML
<tr>
    <td>1</td>
    <td>
        <input type="radio" name="rbtnAttendance1" />Present
        <input type="radio" name="rbtnAttendance1" />Absent
    </td>
</tr>
<tr>
    <td>2</td>
    <td>
        <input type="radio" name="rbtnAttendance2" />Present
        <input type="radio" name="rbtnAttendance2" />Absent
    </td>
</tr>


This way you can only select one option from the radio buttons with same name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900