大家帮忙看看为什么我的checkinformation()函数不能被触发?急急急!
<?php
if(!empty($_POST["btnsubmit"])){
$link=mysql_connect("localhost","root","123456789") or die(mysql_error());
mysql_select_db(member,$link);
$sql="insert into stu_information values({$_POST['num']},\"{$_POST['name']}\",\"{$_POST['sex']}\",\"{$_POST['birthday']}\",\"{$_POST['major']}\",\"{$_POST['class']}\",\"{$_POST['check']}\",\"{$_POST['email']}\")";
$rs=mysql_query($sql,$link) or die(mysql_error());
$sn=mysql_affected_rows($link);
$msg=($sn==1)? "添加记录成功!":"添加记录失败!";
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
<!--
function check(){
if(form1.num.value==""){
alert("学号不能为空,请输入学号!");
form1.num.focus();
return false;}
if(form1.name.value==""){
alert("姓名不能为空,请输入姓名!");
form1.name.focus();
return false;}
if(form1.birthday.value==""){
alert("出生日期不能为空,请输入出生日期!");
form1.birthday.focus();
return false;}
if(form1.class.value==""){
alert("出生日期不能为空,请输入出生日期!");
return false;}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="return check()">
<table align="center" border="0" cellpadding="3">
<caption align="center"><font color="#FF0000" size="+2" face="方正行楷简体">学生信息录入界面</font></caption>
<tr>
<th scope="row">学号:</th><td><input type="text" name="num"/></td>
</tr>
<tr>
<th scope="row">姓名:</th><td><input type="text" name="name"/></td>
</tr>
<tr>
<th scope="row">性别:</th><td><input type="radio" name="sex" value="男"/>男<input type="radio" name="sex" value="女"/>女</td>
</tr>
<tr>
<th scope="row">出生日期:</th><td><input type="text" name="birthday"/></td>
</tr>
<tr>
<th scope="row">专业:</th>
<td>
<select name="major" size="1">
<option value="0" selected="selected">--请选择--</option>
<option value="电子信息工程">电子信息工程</option>
<option value="通信" >通信</option>
<option value="自动化">自动化</option>
<option value="电气自动化">电气自动化</option>
<option value="仪器">仪器</option>
</select>
</td>
</tr>
<tr>
<th scope="row">班级:</th><td><input type="text" name="class"/></td>
</tr>
<tr>
<th scope="row">是否团员:</th><td><input type="checkbox" name="check" value="yes"></td>
</tr>
<tr>
<th scope="row">电子信箱:</th><td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="btnsubmit" type="submit" value="提交"/>
<input type="reset" name="reset1" value="重置" />
</tr>
<tr><td colspan="2" align="center"><font color="red">
<?php echo $msg;?></font></td></tr>
</table>
</form>
</body>
</html>
<?php
if(!empty($_POST["btnsubmit"])){
$link=mysql_connect("localhost","root","123456789") or die(mysql_error());
mysql_select_db(member,$link);
$sql="insert into stu_information values({$_POST['num']},\"{$_POST['name']}\",\"{$_POST['sex']}\",\"{$_POST['birthday']}\",\"{$_POST['major']}\",\"{$_POST['class']}\",\"{$_POST['check']}\",\"{$_POST['email']}\")";
$rs=mysql_query($sql,$link) or die(mysql_error());
$sn=mysql_affected_rows($link);
$msg=($sn==1)? "添加记录成功!":"添加记录失败!";
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
<!--
function check(){
if(form1.num.value==""){
alert("学号不能为空,请输入学号!");
form1.num.focus();
return false;}
if(form1.name.value==""){
alert("姓名不能为空,请输入姓名!");
form1.name.focus();
return false;}
if(form1.birthday.value==""){
alert("出生日期不能为空,请输入出生日期!");
form1.birthday.focus();
return false;}
if(form1.class.value==""){
alert("出生日期不能为空,请输入出生日期!");
return false;}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="return check()">
<table align="center" border="0" cellpadding="3">
<caption align="center"><font color="#FF0000" size="+2" face="方正行楷简体">学生信息录入界面</font></caption>
<tr>
<th scope="row">学号:</th><td><input type="text" name="num"/></td>
</tr>
<tr>
<th scope="row">姓名:</th><td><input type="text" name="name"/></td>
</tr>
<tr>
<th scope="row">性别:</th><td><input type="radio" name="sex" value="男"/>男<input type="radio" name="sex" value="女"/>女</td>
</tr>
<tr>
<th scope="row">出生日期:</th><td><input type="text" name="birthday"/></td>
</tr>
<tr>
<th scope="row">专业:</th>
<td>
<select name="major" size="1">
<option value="0" selected="selected">--请选择--</option>
<option value="电子信息工程">电子信息工程</option>
<option value="通信" >通信</option>
<option value="自动化">自动化</option>
<option value="电气自动化">电气自动化</option>
<option value="仪器">仪器</option>
</select>
</td>
</tr>
<tr>
<th scope="row">班级:</th><td><input type="text" name="class"/></td>
</tr>
<tr>
<th scope="row">是否团员:</th><td><input type="checkbox" name="check" value="yes"></td>
</tr>
<tr>
<th scope="row">电子信箱:</th><td><input type="text" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="btnsubmit" type="submit" value="提交"/>
<input type="reset" name="reset1" value="重置" />
</tr>
<tr><td colspan="2" align="center"><font color="red">
<?php echo $msg;?></font></td></tr>
</table>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/javascript">
<!--
function checkform(){
var form1 = document.form1; if(form1.num.value==""){
alert("学号不能为空,请输入学号!");
form1.num.focus();
return false;
}
if(form1.name.value==""){
alert("姓名不能为空,请输入姓名!");
form1.name.focus();
return false;
}
if(form1.birthday.value==""){
alert("出生日期不能为空,请输入出生日期!");
form1.birthday.focus();
return false;
}
if(form1.class.value==""){
alert("出生日期不能为空,请输入出生日期!");
return false;
}
return true;
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="return checkform()">
<table align="center" border="0" cellpadding="3">
<caption align="center"> <font color="#FF0000" size="+2" face="方正行楷简体">学生信息录入界面 </font> </caption>
<tr>
<th scope="row">学号: </th> <td> <input type="text" name="num"/> </td>
</tr>
<tr>
<th scope="row">姓名: </th> <td> <input type="text" name="name"/> </td>
</tr>
<tr>
<th scope="row">性别: </th> <td> <input type="radio" name="sex" value="男"/>男 <input type="radio" name="sex" value="女"/>女 </td>
</tr>
<tr>
<th scope="row">出生日期: </th> <td> <input type="text" name="birthday"/> </td>
</tr>
<tr>
<th scope="row">专业: </th>
<td>
<select name="major" size="1">
<option value="0" selected="selected">--请选择-- </option>
<option value="电子信息工程">电子信息工程 </option>
<option value="通信" >通信 </option>
<option value="自动化">自动化 </option>
<option value="电气自动化">电气自动化 </option>
<option value="仪器">仪器 </option>
</select>
</td>
</tr>
<tr>
<th scope="row">班级: </th> <td> <input type="text" name="class"/> </td>
</tr>
<tr>
<th scope="row">是否团员: </th> <td> <input type="checkbox" name="check" value="yes"> </td>
</tr>
<tr>
<th scope="row">电子信箱: </th> <td> <input type="text" name="email"/> </td>
</tr>
<tr>
<td colspan="2" align="center"> <input name="btnsubmit" type="submit" value="提交" />
<input type="reset" name="reset1" value="重置" />
</tr>
<tr> <td colspan="2" align="center"> <font color="red">
</font> </td> </tr>
</table>
</form></body>
</html>
而是 check()函数
这个 check()函数名与单选钮
<th scope="row">是否团员: </th> <td> <input type="checkbox" name="check" value="yes"> </td>
命名冲突
IE下运行一下,有错误提示:
26行缺少标识符
找到26号:
if(form1.class.value==""){class是js里的关键词,你不能用的你把65行改成:
<th scope="row">班级: </th> <td> <input type="text" name="test"/> </td>
然后26行:if(form1.test.value==""){
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/javascript">
<!--
function checkform(form1){ if(form1.num.value==""){
alert("学号不能为空,请输入学号!");
form1.num.focus();
return false;
}
if(form1.name.value==""){
alert("姓名不能为空,请输入姓名!");
form1.name.focus();
return false;
}
if(form1.birthday.value==""){
alert("出生日期不能为空,请输入出生日期!");
form1.birthday.focus();
return false;
}
if(form1.class.value==""){
alert("出生日期不能为空,请输入出生日期!");
return false;
}
}
-->
</script>
</head>
<body>
<form name="form1" action="" method="post" onsubmit="return checkform(this);">
<table align="center" border="0" cellpadding="3">
<caption align="center"> <font color="#FF0000" size="+2" >学生信息录入界面 </font> </caption>
<tr>
<th scope="row">学号: </th> <td> <input type="text" name="num"/> </td>
</tr>
<tr>
<th scope="row">姓名: </th> <td> <input type="text" name="name"/> </td>
</tr>
<tr>
<th scope="row">性别: </th> <td> <input type="radio" name="sex" value="男"/>男 <input type="radio" name="sex" value="女"/>女 </td>
</tr>
<tr>
<th scope="row">出生日期: </th> <td> <input type="text" name="birthday"/> </td>
</tr>
<tr>
<th scope="row">专业: </th>
<td>
<select name="major" size="1">
<option value="0" selected="selected">--请选择-- </option>
<option value="电子信息工程">电子信息工程 </option>
<option value="通信" >通信 </option>
<option value="自动化">自动化 </option>
<option value="电气自动化">电气自动化 </option>
<option value="仪器">仪器 </option>
</select>
</td>
</tr>
<tr>
<th scope="row">班级: </th> <td> <input type="text" name="class"/> </td>
</tr>
<tr>
<th scope="row">是否团员: </th> <td> <input type="checkbox" name="check" value="yes"> </td>
</tr>
<tr>
<th scope="row">电子信箱: </th> <td> <input type="text" name="email"/> </td>
</tr>
<tr>
<td colspan="2" align="center"> <input name="btnsubmit" type="submit" value="提交" />
<input type="reset" name="reset1" value="重置" />
</tr>
<tr> <td colspan="2" align="center"> <font color="red">
</font> </td> </tr>
</table>
</form></body>
</html>