我一个js表单验证不通过时,点登陆会提示,但还是会提交。怎么修改代码才能验证不通过就不提交?

这是详细的代码:
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>登陆</title>
</head>
<body>
<script language = "javascript" type="text/javascript">
function check(){
if(f1.username.value == "")
{
alert("用户名为空!");
form.username.focus();
return false;
}
if(f1.password.value == "")
{
alert("请输入密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<center>
<h1>欢迎来到论坛!</h1><br>
<form name = "f1" action = "login.jsp" method="post" onsubmit = "return check()">
<table border="1">
<tr>
<td width="30%"><center>用户名:</center></td>
<td width="70%"><input type="text" name="username"></td>
</tr>
<tr>
<td><center>密码:</center></td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan = "2">
<center>
<input type="submit" name = "submit" value="登录">
<input type="button" value="注册" onclick = "window.location.href='zhuce.jsp'">
</center>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

form.username.focus();
form.password.focus();

改成 f1.username.focus();form.password.focus();
温馨提示:答案为网友推荐,仅供参考