代码如下:为了使不同题目能够分别选中,我设置的radio的名字为="<%=tihao%>"
while(rs1.next())
{
id=rs1.getString("id");
String neir=rs1.getString("neir");
%>
<tr>
<td>
<input type="radio" name="<%=tihao%>" value="<%=id%>" >
<%=neir%>
</td>
</tr>
<%
}
while(rs1.next())
{
id=rs1.getString("id");
String neir=rs1.getString("neir");
%>
<tr>
<td>
<input type="radio" name="<%=tihao%>" value="<%=id%>" >
<%=neir%>
</td>
</tr>
<%
}
<input type="radio" name="test" id="<%=tihao%>" value="<%=id%>">String tihao = request.getParameter("test");
1 title
单选框 xx
单选框 xx
单选框 xx
单选框 xx
2 title
单选框 xx
单选框 xx
单选框 xx
单选框 xx
如果按照楼上所说,8个选项只能选择1个了,我希望是每个题目选一个,所以使用了
<input type="radio" name="<%=tihao%>" value="<%=id%>" >
你只要把每个题生成的一组单选按钮的name设置成一样就可以了!
提交是
提交到哪个action就在那个action 获取request就可以
<input type="radio" name="title1" id="<%=tihao%>" value="<%=id%>">
这个逻辑应该不是什么大问题,只是不了解你底层的数据库如何设计。
建议将所radio的name加一个前缀名。如:question_<%=tihao%>
用request.getParameterMap()取到所有的请求表单值,
然后遍历出question_为前缀的就可以了。
然后遍历出question_为前缀的就可以了。????怎样遍历呢?
<input type="radio" name="<%=selectName%>" value="1">
<input type="radio" name="<%=selectName%>" value="2">
<input type="radio" name="<%=selectName%>" value="3">
<input type="radio" name="<%=selectName%>" value="4">在另一个页面里,count是总题目条数,可以传过去
for(int i=0;i<count;i++){
String tempSelect = "SELECT" + String.valueOf(i);
String select = (String)aInstance.getRequest().getParameter(tempSelect);
if(select.equals("1")) 就是选中了第一个选项
以此类推
另外i=0就是第一道题,以此类推
<input type="radio" name="<%=tihao%>" value="<%=id%>" >
不能设置value的数值为1,2,3,4
id tihao leix neir tnum
1 1 0 xx 1
2 1 0 xx 1
3 1 0 xx 1
4 1 0 xx 1
5 2 0 xx 2
6......
tnum为计数的,比如选中tihao为1中的2,则第2行的tnum加1。
<INPUT TYPE="hidden" NAME=selectId ID=selectId VALUE=<%=ID %>>
然后再用我前面的方法
<input type="radio" name="<%=selectName%>" value="1">
<input type="radio" name="<%=selectName%>" value="2">
<input type="radio" name="<%=selectName%>" value="3">
<input type="radio" name="<%=selectName%>" value="4">
...在另一个页面里,你用
String[] sKey= (String [])(aInstance.getRequest().getParameterValues("selectId"));
可以得到id的数组
sKey[i]就是第i道的题目的id
我那代码是我从java里拷出来,自己写的得到request的方法,
不要误会,不好意思,呵呵。
你在处理时循环处理,每个id对应的选项选了哪个也可以相关得到的呀
在另一个页面里,count是总题目条数,可以传过去
for(int i=0;i<count;i++){
String tempSelect = "SELECT" + String.valueOf(i);
String select = (String)aInstance.getRequest().getParameter(tempSelect);
if(select.equals("1")) 就是选中了第一个选项
以此类推
另外i=0就是第一道题,以此类推sKey[i]就是第i道题的id
<input type="radio".... id = "xxx2">用document.getElementById("xxx1")
document.getElementById("xxx2")指哪打哪~~~~~~
你说的单独看起来我都明白,可是联合起来用就不大清楚思路了,我是初学哈。你在处理时循环处理,每个id对应的选项选了哪个也可以相关得到的呀(怎么关联得到呢??)
for(int i=0;i<count;i++){
String tempSelect = "SELECT" + String.valueOf(i);
String select = (String)aInstance.getRequest().getParameter(tempSelect);
if(select.equals("1")) 就是选中了第一个选项
select这个和sKey怎么结合用??
for(int i=0;i<count;i++){
String tempSelect = "SELECT" + String.valueOf(i);
String id = sKey[i];//得到题目id
//下面是该id对应题目的选项处理
String select = (String)aInstance.getRequest().getParameter(tempSelect);
if(select.equals("1")){ //就是选中了第一个选项
处理...
}else if(select.equals("2")){
处理...
}
...}
这么写能明白吗?
<input type="radio" name="<%=tihao%>" value="<%=id%>" >
在另外一个页面
for(int i=0;i<count;i++)
{
String tempSelect =String.valueOf(i+1);
String select = request.getParameter(tempSelect);
System.out.println(select);
String sql="Update toupiaonr set tpnum=tpnum+1 where id='"+select+"'";
login.executeUpdate(sql);
}
不过问题是选择每道题目第一项时select的数值通过System.out.println(select)是选择的那几项,可是在update后,数据库中把每道题的1,2项都加1了。
如果选择的是每到题的2,3,4就可以正确增加,好奇怪哟!!