提交表单时执行func方法实现代码
<%@ page contentType="text/html; charset=utf-8"%>
<!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=utf-8" />
<title>用户注册</title>
<script language="javascript">
<!--
function MyForm(){
msg.innerHTML="debug::in function";
var username = document.form1.username.value;
var msg = document.getElementById("msg");
if(username.length==0){
msg.innerHTML="[ 提示:用户名不能为空! ]";
document.form1.username.focus();
return false;
}
var pass = document.form1.password.value;
if(pass.length==0){
msg.innerHTML="[ 提示:密码不能为空! ]";
document.form1.password.focus();
return false;
}
var pass1 = document.form1.password1.value;
if(pass1.length==0){
msg.innerHTML="[ 提示:确认密码不能为空! ]";
document.form1.password1.focus();
return false;
}
if(pass1!=pass){
msg.innerHTML="[ 提示:您两次输入的密码不一致! ]";
document.form1.passwoid.focus();
return false;
}
var mail = document.form1.mail.value;
if(mail.length==0){
msg.innerHTML="[ 提示:E_mail不能为空! ]";
document.form1.mail.focus();
return false;
}
var i = form1.mail.value.indexOf("@");
var j = form1.mail.value.indexOf(".");
if((i<0)||(j<0)||(i-j>0))
{
msg.innerHTML="[ 提示:您输入的E_mail格式不正确,请正确输入! ]";
document.form1.mail.focus();
return false;
}
msg.innerHTML="";
return true;
}
-->
</script>
</head>
<body onload="document.form1.username.focus()">
<form id="form1" name="form1" method="post" action="" onsubmit="return MyForm()">
<table width="389" border="1" align="center" cellpadding="5">
<tr>
<td colspan="2"><div align="center">用户注册<br /></div></td>
</tr>
<tr>
<td colspan="2" align="center" bordercolor=""
bgcolor="">
<font color="red"><span id="msg">${error}</span> </font>
</td>
</tr>
<tr>
<td width="71">用户名:</td>
<td width="286"><label>
<input name="username" type="text" id="username" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>用户密码:</td>
<td><label>
<input name="password" type="password" id="password" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>重复密码:</td>
<td><label>
<input name="password1" type="password" id="password1" size="20" />
</label>
*(必填)</td>
</tr>
<tr>
<td>电子邮件:</td>
<td><label>
<input name="mail" type="text" id="mail" size="25" />
</label>
*(必填)</td>
</tr>
<tr>
<td>电话:</td>
<td><label>
<input name="tel" type="text" id="tel" size="22" />
</label></td>
</tr>
<tr>
<td>QQ:</td>
<td><label>
<input name="qq" type="text" id="qq" size="22" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="submit" name="Submit" value="注册" />
<input type="reset" name="Submit2" value="重置" />
</div>
</label></td>
</tr>
</table>
</form>
</body>
</html>