菜鸟级问题~~~~ onsubmit事件~~~
我弄的一个表单的判断咋会不执行呢?
<script language= "JavaScript ">
function checkdata(){
if ((form.user_id.value)== ' ') {
alert( "\【用户名称】不能为空,请正确填写!! ");
form.user_id.focus();
return false;
}
if ((form.user_Unit.value)== ' ') {
alert( "\【用户地址】不能为空,请正确填写!! ");
form.user_Unit.focus();
return false;
}
}
</script>
.....................................
<Script Language = "JavaScript ">
alert( "此用户资料录入成功! ");
self.navigate( "user_sj.asp?user_id= <%=rs( "user_id ")%> ")
</Script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<form method= "POST " action= "user_data.asp?action=save " name=form onsubmit= "return checkdata(); ">
.....................................
<input type= "submit " value= "提交 " name= "B1 " class=input>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
不会执行checkdata(),即使不录入 "用户名称 "及 "用户地址 ",也会直接到~~alert( "祝贺你,此用户资料录入成功! ");~转入另一个页面;
各位,帮忙看一下吧~~
------解决方案-------------------- <script language= "JavaScript ">
function checkdata(){
if ((form.user_id.value)== ' ') {
alert( "\【用户名称】不能为空,请正确填写!! ");
form.user_id.focus();
return false;
}
if ((form.user_Unit.value)== ' ') {
alert( "\【用户地址】不能为空,请正确填写!! ");
form.user_Unit.focus();
return false;
}
return true;
}
// 这个函数在保存成功后在调用,
function SaveSucceed()
{
alert( "此用户资料录入成功! ");
self.navigate( "user_sj.asp?user_id= <%=rs( "user_id ")%> ")
}
</script>
------解决方案--------------------javascript一般是用来判断用户填写是否规范!
所以在正确录入的时候就可以下面这样:
<%
code
...
response.write( " <Script Language = "JavaScript "> alert( '此用户资料录入成功! ');self.navigate( 'xxx ') </Script> ")
%>