JavaScript函数不能触发是什么原因

hj7518 2009-11-12 08:06:59
大家帮忙看看为什么我的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>


...全文
185 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hj7518 2009-11-13
  • 打赏
  • 举报
回复
但是函数名是不同的呀,一个是checkform(),一个名字是check,怎么会出现调用问题了?如果是js被禁用了,改怎么办?不会是这个问题吧》
xuzuning 2009-11-13
  • 打赏
  • 举报
回复
你定义和调用的不是 checkform()函数
而是 check()函数
这个 check()函数名与单选钮
<th scope="row">是否团员: </th> <td> <input type="checkbox" name="check" value="yes"> </td>
命名冲突
搬运工865 2009-11-13
  • 打赏
  • 举报
回复
同上
LuciferStar 2009-11-13
  • 打赏
  • 举报
回复
JS被禁用了?
hj7518 2009-11-13
  • 打赏
  • 举报
回复
也谢谢各位的不辞辛苦。
hj7518 2009-11-13
  • 打赏
  • 举报
回复
baiyuxiong 谢谢你,你帮我解决了问题。
alandy 2009-11-13
  • 打赏
  • 举报
回复
楼主拿分来~~~~
alandy 2009-11-13
  • 打赏
  • 举报
回复
<!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(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>
codeyell-com 2009-11-13
  • 打赏
  • 举报
回复
so easy
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==""){
hj7518 2009-11-12
  • 打赏
  • 举报
回复
我按你的代码试过了,还是不行,不能触发checkform()函数。
phpboy 2009-11-12
  • 打赏
  • 举报
回复

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

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧