在此代码中,所有的无线电按钮都会被检查 [英] In this code all the radiobuttons are getting checked

查看:52
本文介绍了在此代码中,所有的无线电按钮都会被检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此代码中,所有的无线电按钮都会被检查。我希望在所有行中检查任何一个radiobutton。

请帮助我。



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.

<%@ 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>

推荐答案

用以下内容替换您的单选按钮代码,
Replace your radio button code with the following,
<input type="radio" name="presenceFor1" />

为每一行指定唯一的名称,并为单选按钮的行中的每个td指定相同的名称。

阅读 W3C [ ^ ]更多想法。



-KR

Give unique name for each row, and same name for each td in row for radio buttons.
Read W3C[^] for more idea.

-KR


您可以简单地为相应的无线电组提供相同的名称,以达到以下目的:



You can simply give the same name to the respective radio groups to achieve this like:

<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.


这篇关于在此代码中,所有的无线电按钮都会被检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆