<script language="javascript">
function clicked()
{
for(var i=0;i<document.mxh.radio.length;i++)
{
if(document.mxh.radio[i].checked)
alert(document.mxh.radio[i].value+":选了")
else
alert(document.mxh.radio[i].value+":没选") }
}
</script><form name=mxh>
<input type=radio name=radio value=1>1
<input type=radio name=radio value=2>2
<input type=radio name=radio value=3>3
<input type=radio name=radio value=4>4
<input type=radio name=radio value=5>5
<input type=button value="查询" onclick=clicked()>
</form>
function clicked()
{
for(var i=0;i<document.mxh.radio.length;i++)
{
if(document.mxh.radio[i].checked)
alert(document.mxh.radio[i].value+":选了")
else
alert(document.mxh.radio[i].value+":没选") }
}
</script><form name=mxh>
<input type=radio name=radio value=1>1
<input type=radio name=radio value=2>2
<input type=radio name=radio value=3>3
<input type=radio name=radio value=4>4
<input type=radio name=radio value=5>5
<input type=button value="查询" onclick=clicked()>
</form>
function check(VALUE) {
var radioArr=eval("document.forms[0]."+VALUE);
var radioValue;
var j;
for(var i=0;i<radioArr.length;i++){
radioValue=eval("document.forms[0]."+VALUE+"["+i+"]");
if(radioValue.checked) j++;
}
if(j=0) then alert("no select");
}
</script> <p>
<input type="radio" value="V1" checked name="R1">
<input type="radio" value="V1" checked name="R1">
<input type="radio" value="V1" checked name="R1">
<input type="radio" value="V1" checked name="R1"> <input type="button" value="提交" name="B1" onclick="check('R1')">
<script language="javaScript">
function check()
{
for(var i=0;i<document.AssignedDisp.requestId.length;i++)
{
if (!(document.AssignedDisp.requestId[i].checked))
{
alert(document.AssignedDisp.requestId[i].value+":ûѡ");
return false;
}
return true;
}
</script>
function check()
{
for(var i=0;i<document.AssignedDisp.requestId.length;i++)
{
if !(document.AssignedDisp.requestId[i].checked)
{
alert(document.AssignedDisp.requestId[i].value+":没选¡");
return false;
}
return true;
}
</script>
噢,不对,怎么看都像少了一个"}"
你的方法也不行 啊,不知道为什么啊????
还有我的radio的name是group_id"+groupId+" <input type=radio name=group_id"+groupId+" value="+userId+">";
radio的name要是一组的话,必须是相同的。
再有问题call 我:
010-68816215
有qq号么,告诉我,或在这里写出来啊,
单个的还行,但是多个合起来就不行了,
<script language="javascript">
var ss=""
function clicked()
{
for(var i=0;i<document.mxh.elements.length;i++)
{
if((document.mxh.elements[i].type).toLowerCase()=="radio" && !(document.mxh.elements[i].checked))
ss+=document.mxh.elements[i].value+":没选\n"
}
alert("您没有选的总数为:\n\n"+ss)
}
</script><form name=mxh>
<input type=radio name=radio value=a>a
<input type=radio name=radio value=b>b
<input type=radio name=radio value=c>c
<input type=radio name=radio value=d>d
<input type=radio name=radio value=e>e
<p>
<input>
<p>
<input type=radio name=radio1 value=aa>aa
<input type=radio name=radio1 value=bb>bb
<input type=radio name=radio1 value=cc>cc
<input type=radio name=radio1 value=dd>dd
<input type=radio name=radio1 value=ee>ee
<input type=button value="查询" onclick=clicked()>
</form></HTML>
<html>
<body>
<head>
<script language="javascript">
function clicked()
{
var a=0,b=0,c=0;
for(var i=0;i<document.mxh.requestId.length;i++)
{
if(document.mxh.requestId[i].checked)
a++;
}
if(a==0)
{
alert("YOU must selelt one Item")
}
for(var j=0;j<document.mxh.groupid.length;j++)
{
if(document.mxh.groupid[j].checked)
b++;
}
if(b==0)
{
alert("YOU must selelt one Item")
}
for(var k=0;k<document.mxh.group_id"+groupId+".length;k++)
{
if(document.mxh.group_id"+groupId+"[k].checked)
c++;
}
if(c==0)
{
alert("YOU must selelt one Item")
}}
</script>
</head>
<input type=radio name=requestId value="+requestId+">
<input type=\"radio\" name=groupid value="+groupId+">
<input type=radio name=group_id"+groupId+" value="+userId+">
</body>
</html>问题是第一个可以,第2个不行,第3个有语法错误,怎么办啊???
<html>
<body>
<head>
<script language="javascript">
function clicked(){
var a=0,b=0,c=0;
for(var i=0;i<document.mxh.elements.length;i++)
{
if(document.mxh.elements[i].checked && (document.mxh.elements[i].name=="requestId"))
a++;
}
if(a==0)
{
alert("YOU must selelt one Item")
}
for(var j=0;j<document.mxh.elements.length;j++)
{
if(document.mxh.elements[j].checked && (document.mxh.elements[j].name=="groupId"))
b++;
}
if(b==0)
{
alert("YOU must selelt one Item")
}
for(var k=0;k<document.mxh.elements.length;k++)
{
if(document.mxh.elements[k].checked && (document.mxh.elements[k].name=="group_id_groupId"))
c++;
}
if(c==0)
{
alert("YOU must selelt one Item")
}}
</script>
<form name=mxh>
<input type=radio name="requestId" value="+requestId+"><br><input type="radio" name="groupId" value="+groupId+"><br><input type="radio" name=group_id_groupId value="+userId+"><br>
<input type=button value="check it" onclick="clicked()">
</form>
<body>
<%@page import="java.io.*"%>
<%@ include file="taskHeader.jsp" %>
<head>
<title>assign task to group</title>
<script language="javascript">
function clicked()
{
var a=0,b=0,c=0;
for(var i=0;i<document.groupDisp.elements.length;i++)
{
if(document.groupDisp.elements[i].checked && (document.groupDisp.elements[i].value=="+requestId+"))
a++;
}
if(a==0)
{
alert("YOU must selelt one Number")
}
for(var j=0;j<document.groupDisp.elements.length;j++)
{
if(document.groupDisp.elements[j].checked && (document.groupDisp.elements[j].value=="+groupId+"))
b++;
}
if(b==0)
{
alert("YOU must selelt one Group Name!")
}
for(var k=0;k<document.groupDisp.elements.length;k++)
{
if(document.groupDisp.elements[k].checked && (document.groupDisp.elements[k].value=="+userId+"))
c++;
}
if(c==0)
{
alert("YOU must selelt one User Name!")
}
}
</script>
</head>
<%@ include file="taskHeader2.jsp" %>
<%
try {
con.connect();
java.sql.ResultSet myRs;
%><%--
check for the post method and save the assignment to database
--%>
<%
if(request.getParameter("submit")!=null){
String requestId=request.getParameter("requestId");
String groupId="";
String transcriberId="";
String supervisorId="";
java.util.Enumeration e=request.getParameterNames();
while(e.hasMoreElements()){
String param=e.nextElement().toString();
if(param.indexOf("groupid")>=0){
groupId=request.getParameter("groupid");
String tranStr="group_id"+groupId;
boolean hasSuper=false;
myRs=con.select("select userId from userGroup where groupId="+groupId);
int tmpId=-1;
while(myRs.next()){
tmpId=myRs.getInt("userId");
java.sql.Statement st1=con.con.createStatement();
java.sql.ResultSet rs1=st1.executeQuery("select userId from users where sysGroupId=2 and userId="+tmpId);
while(rs1.next()){
hasSuper=true;
supervisorId=rs1.getString("userId");
}
}
if((transcriberId=request.getParameter(tranStr).toString())!=null){
String sqlStr="";
java.util.GregorianCalendar mycal=new java.util.GregorianCalendar();
java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
String dateStr=formatter.format(mycal.getTime());
if(hasSuper){
//if supervisorId=transcriberId means assign to just group,the supervisor assign it to transcriber later.
if(Integer.valueOf(supervisorId).intValue()==Integer.valueOf(transcriberId).intValue()){
sqlStr="update request set supervisorId="+supervisorId+",assignTime='"+dateStr+"' where requestId="+requestId;
}else{
sqlStr="update request set status=2,supervisorId="+supervisorId+",transcriberId="+transcriberId+",assignTime='"+dateStr+"' where requestId="+requestId;
}
}else{
sqlStr="update request set status=2,transcriberId="+transcriberId+",assignTime='"+dateStr+"' where requestId="+requestId;
}
con.update(sqlStr);
}//if
}//if
}//while
}//if
%><%--
list the not assigned tasks and the group and transcriber and their existing tasks;
--%>
<%
for(int j=0;j<2;j++){
out.println("<br>");
}
//get the url path from sysConfigure
String urlPath="";
myRs=con.select("select confValue from sysConfigure where confName=\'urlPath\'");
while(myRs.next()){
urlPath=myRs.getString("confValue");
}
out.println("<form name=groupDisp method=post action=\"assignToGroup.jsp\">");
out.println("<center>");
out.println("<font size=4>");
//list the not assigned tasks:
out.println("<font color=darkblue size=5><B><I>Not assigned tasks</I></b></font>");
out.println("<table name=notAssigned border=1>");
int requestId;
int clientId;
int supervisorId;
String requestTime="";
String year="",month="",day="";
int returnDate;
int inputLang,outputLang;
String subject="";
int status,audioLen,docLen;
String settle="";
String clientName="";
out.println("<tr>");
out.println("<td>Number</td><td>Client Name</td><td>Request Time</td><td>Requested Turnaround Time</td><td>Language</td><td>Subject</td><td>Settled</td><td>Attachment</td>");
out.println("</tr>");
String sqlStr="select a.requestId requestId,a.clientId clientId,a.introduce,a.supervisorId supervisorId,";
sqlStr=sqlStr+"a.transcriberId transcriberId,a.requestTime requestTime,a.returnDate returnDate,";
sqlStr=sqlStr+"a.inputLang inputLang,a.outputLang outputLang,a.status status,a.audioLen audioLen,";
sqlStr=sqlStr+"a.docLen docLen,a.settle settle,b.userName clientName ";
sqlStr=sqlStr+" from request as a,users as b";
sqlStr=sqlStr+" where a.status=1 and a.clientId=b.userId and (supervisorId=0 or supervisorId is null) and parent<>-1";
myRs=con.select(sqlStr);
int tableCount=0;
while(myRs.next()){
tableCount++;
requestId=myRs.getInt("requestId");
clientId=myRs.getInt("clientId");
supervisorId=myRs.getInt("supervisorId");
requestTime=myRs.getString("requestTime");
year=requestTime.substring(0,4);
month=requestTime.substring(4,6);
day=requestTime.substring(6,8);
String hour="",minute="";
hour=requestTime.substring(8,10);
minute=requestTime.substring(10,12);
requestTime=year+"-"+month+"-"+day+" "+hour+":"+minute;
returnDate=myRs.getInt("returnDate");
inputLang=myRs.getInt("inputLang");
//outputLang=myRs.getInt("outputLang");
subject=myRs.getString("introduce");
status=myRs.getInt("status");
settle=myRs.getString("settle");
clientName=myRs.getString("clientName");
out.println("<tr>");
out.println("<td width=60>");
String tmpString="<input type=radio name=requestId value="+requestId+">";
out.println(tmpString);
out.println(tableCount+"</td>");
out.println("<td>"+clientName+"</td>");
out.println("<td>"+requestTime+"</td>");
out.println("<td>"+returnDate+"</td>");
out.println("<td>"+util.getLanguage(inputLang)+"</td>");
//out.println("<td>"+util.getLanguage(outputLang)+"</td>");
out.println("<td>"+subject+"</td>");
out.println("<td>"+settle+"</td>");
out.println("<td>");
out.println("<table name=table"+tableCount+" border=1>");
//out.println("<tr><td>File Name</td><td>File Type</td></tr>");
String fileName="",fileLocation="";
java.sql.Statement stmt = con.con.createStatement();
java.sql.ResultSet rest =stmt.executeQuery("select * from attachment where requestId="+requestId+" order by type");
while (rest.next()) {
fileName=rest.getString("fileName");
fileLocation=rest.getString("fileLocation");
out.println("<tr>");
out.println("<td width=180>");
out.println("<a href=\""+urlPath+fileLocation+"\">"+convertor.AsciiToChineseString(fileName)+"</a></td>");
int fileType=rest.getInt("type");
switch(fileType){
case 1:
out.println("<td width=180>Audio File</td>");
break;
case 2:
out.println("<td width=180>Document for translation</td>");
break;
case 3:
out.println("<td width=180>Glossary</td>");
break;
case 4:
out.println("<td width=180>Transcript Format</td>");
break;
case 5:
out.println("<td width=180>Hyperlink</td>");
break;
case 6:
out.println("<td width=180>Transcript/Translated Doc</td>");
break;
case 7:
out.println("<td width=180>Other attachments</td>");
break;
}
out.println("</tr>");
}//while(rest)
out.println("</table>");//attachment table
out.println("</td>");
out.println("</tr>");
}
out.println("</table>");
for(int k=0;k<3;k++){
out.println("<br>");
}
out.println("<b><I><font size=5><center>To Group:</center></font></I></b>");
out.println("<table name=transDisp border=1>");
out.println("<tr>");
int i=0;
String groupStr;
myRs=con.select("select distinct groupId from userGroup");
out.println("<td width=120>Group Name</td><td width=700>Stuff</td>");
out.println("</tr>");
while (myRs.next()) {
i++;
out.println("<tr><td width=120>");
int groupId=myRs.getInt("groupId");
String tmp="<input type=\"radio\" name=groupid value="+groupId+">";
out.println(tmp);
java.sql.Statement st1 = con.con.createStatement();
java.sql.ResultSet rs1 =st1.executeQuery("select groupName from groups where groupId=" + groupId);
while (rs1.next()) {
out.println(rs1.getString("groupName")+"</td>");
}
out.println("<td>");
out.println("<table border=1>");
out.println("<tr>");
out.println("<td width=200>User Name</td><td width=100>Role</td><td width=100>Status</td><td width=500>Existing Tasks</td>");
out.println("</tr>");
int count2=0;
java.sql.Statement st2 = con.con.createStatement();
java.sql.ResultSet rs2 =st2.executeQuery("select distinct userId from userGroup where groupId=" + groupId);
while (rs2.next()) {
int userId=rs2.getInt("userId");
boolean bSuper=false; java.sql.Statement st3 = con.con.createStatement();
java.sql.ResultSet rs3 =st3.executeQuery("select userName,sysGroupId,AcctDisable from users where userId=" + userId+" and (sysGroupId=2 or sysGroupId=4) order by sysGroupId");
while (rs3.next()) {
out.println("<tr><td width=200>");
String tmp2="<input type=radio name=group_id"+groupId+" value="+userId+">";
out.println(tmp2);
out.println(rs3.getString("userName")+"</td>");
int sysGroupId=rs3.getInt("sysGroupId");
switch(sysGroupId){
case 2:
out.println("<td width=100><font color=red><b>Supervisor</b></font></td>");
bSuper=true;
break;
case 3:
out.println("<td width=100>Client</td>");
break;
case 4:
out.println("<td width=100> Transcriber</td>");
break;
default:
out.println("<td width=100>Unknown</td>");
}
int acctDisable=rs3.getInt("AcctDisable");
switch(acctDisable){
case 0:
out.println("<td width=100>Active</td>");
break;
case 1:
out.println("<td width=100>Disable for login failing</td>");
break;
case 2:
out.println("<td width=100>Disable for not paying</td>");
break;
default:
out.println("<td width=100>Disble</td>");
}
//LIST THE TASKS OF THE TRANSCRIBER THAT HAVE BE ASSIGNED TO HIM
out.println("<td width=500>");
int tasks=0;
int taskId=0;
out.println("<table name=transTask"+userId+">");
java.sql.Statement st4 = con.con.createStatement();
java.sql.ResultSet rs4;
//java.sql.ResultSet rs4 =st4.executeQuery("select requestId from request where transcriberId=" + userId+" or supervisorId="+userId);
if(bSuper){
rs4 =st4.executeQuery("select requestId from request where supervisorId="+userId+" and transcriberId is null");
}else{
rs4 =st4.executeQuery("select requestId from request where transcriberId=" + userId);
}
while (rs4.next()) {
tasks++;
String taskName="";
taskId=rs4.getInt("requestId");
java.sql.Statement st5 = con.con.createStatement();
java.sql.ResultSet rs5 =st5.executeQuery("select fileName,fileLocation from attachment where requestId="+taskId+" and (type<=3)");
while (rs5.next()) {
taskName=taskName+" "+"<a href="+urlPath+rs5.getString("fileLocation")+">"+convertor.AsciiToChineseString(rs5.getString("fileName"))+"</a>";
}
out.println("<tr><td width=300>");
out.println(tasks+":"+taskName);
out.println("</td></tr>");
}
out.println("</table>");
out.println("</td>");
//end of list
out.println("</tr>");
}//while(rs3)
}//while(rs2)
out.println("</table>");
out.println("</td>");
}
out.println("</table>");
out.println("<p align=center><input name=submit type=submit value=Assign onclick=\"javascript:return clicked()\"> <input name=reset type=reset value=Reset></p>");
out.println("</center>");
out.println("</form>");
con.closeConnection();
} catch (java.sql.SQLException e1) {
while (e1 != null) {
out.println("The captured SQL exception is:");
out.println("SQLState: " + e1.getSQLState());
out.println("Message: " + e1.getMessage());
out.println("Vendor: " + e1.getErrorCode());
e1 = e1.getNextException();
}
}
%>
<%@ include file="taskTailer.jsp" %>
</body>
</html>
不管选与不选啊!
有param 很request都不行啊!
怎么办啊!!!????
我只告诉你原理,如果没有选中的话,那个radio的值为null,
你可以通过这个来判断。
在服务器端你可以任何有意义的操作,包括数据库操作,然后,把你的代码输出到客户端,可以包含javascript函数的定义,form的分布个数。你不要把2者混为一谈,你能把你jsp输出的html代码拿出来吗?要是HTML代码不合法的话,那那就是你JSP输出的我问题了
谢谢各位拉,其实如果谁要改的话,只要主要,
form 的name//
radio的name//
就可以了,主要现在是解决这些问题了!
radio的name每组是一个名字,比如,性别的男女是一组,只能是一个名字,因为是单选的,你 不能同时选男又选女。至于如何生成,根据程序需要来定,你不要把把每个radio都起不同的名字,那样失去了单选的意义。这里的name和调用时的必须一致。nane当然可以用程序输出,
比如:
out.println("<input type=radio name=");
out.println var
out.println(">")
见不到你啊!!