<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>聊天室登陆</title>
</head>
<script language="JavaScript">
function check(){
if(chatform.username.value==''){
alert("请输入昵称!");
return false;
}
if(chatform.room.value==''){
alert("请选择房间!");
return false;
}
return true;
}
</script> <body>
<form action="chat.php" name="chatform" method="post" onSubmit="return check()">
昵称:
<input type="text" name="username" value="" size=15>
<input type="radio" name="room" value=1>一号房间
<input type="radio" name="room" value=2>二号房间
<br><br>
<input type="submit" name="submit" value="登陆">
</form>
</body>
</html>请问 当 昵称不为空时,而房间为空,为什么程序还能执行到CHAT.PHP呀?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>聊天室登陆</title>
</head>
<script language="JavaScript">
function check(){
if(chatform.username.value==''){
alert("请输入昵称!");
return false;
}
if(chatform.room.value==''){
alert("请选择房间!");
return false;
}
return true;
}
</script> <body>
<form action="chat.php" name="chatform" method="post" onSubmit="return check()">
昵称:
<input type="text" name="username" value="" size=15>
<input type="radio" name="room" value=1>一号房间
<input type="radio" name="room" value=2>二号房间
<br><br>
<input type="submit" name="submit" value="登陆">
</form>
</body>
</html>请问 当 昵称不为空时,而房间为空,为什么程序还能执行到CHAT.PHP呀?
解决方案 »
- struts2出错Unable to load configuration. - action - file:/D:/workspace/……
- 求个思路
- TOMCAT6.0+JSP本地调试问题:急~~~~
- 急急急!!我用java怎么在服务器端动态生成一个xml文件来供,js调用??
- 报表高手请进,高分求救
- myeclipse+weblogic9,每次一改代码就重启weblogic,如何设置不重启。
- 以前可以运行的,现在怎么不可以了
- java.lang.NoClassDefFoundError和java.lang.OutOfMemoryError
- 这可是个好问题!!(Look!)
- 8080被占用怎么办??
- seesion写入位置问题!
- 菜鸟求教
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>聊天室登陆 </title>
</head>
<script language="JavaScript">
function check(){
if(chatform.username.value==''){
alert("请输入昵称!");
return false;
}
if(!document.chatform.room1.checked&&!document.chatform.room2.checked)
{
alert("请选择房间");
return false;
}
return true;
}
</script> <body>
<form action="chat.php" name="chatform" method="post" onSubmit="return check()">
昵称:
<input type="text" name="username" value="" size=15>
<input type="radio" name="room1" value=1>一号房间
<input type="radio" name="room2" value=2>二号房间
<br> <br>
<input type="submit" name="submit" value="登陆">
</form>
</body>
</html>
room不是text,不能简单的用value==''判断
呵呵。
一般的做法都是:
var radio=document.getElementsByName("room");
然后遍历
设置个标示位,
判断radio[i].checked,如果都没有选中,则返回false。
function check(){
if(chatform.username.value==''){
alert("请输入昵称!");
return false;
}
var rooms = document.getElementsByName("room");
var r = false;
for(var i=0;i<rooms.length;i++){
if(rooms[i].checked){
r=true;
}
}
if(!r) {alert("选择房间"); return false;}return true;
}
</script>