私の問題の役に立つポストを見つけようとしましたが、私の質問が見つかりませんでした。 フォームを検証してデータベースに送信します。そして、これは私のコードです:onsubmitを使用してJavascriptでフォームを検証する
<%@ page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Registration</title>
<link rel="shortcut icon" href="img/icon0.png" />
<link rel="stylesheet" type="text/css" href="../css/index.css" />
<script type="text/javascript">
function validate_form()
{
var isValid = true;
var username = document.getElementById("username").value;
if (username==null||username==""){
alert("WRong input");
isValid = false;
}
if(isValid == true)
{
return true;
}
return false;
}
</script>
</head>
<body>
<form action = "regServlet" method = "POST" onsubmit="return validate_form()">
<table id="regTable">
<tr>
<td class="firstRow">Username:</td>
<td><input type="text" name="username" value="" size="15"/></td>
</tr>
</table>
<input style="margin:auto;" type="image" name="loginB" src="../img/login_button.png" />
</form>
</body>
</html>
それは私がページを実行しているときにTomcat 6 で実行されるJSPファイルです、私のjavascriptの機能がまったく動作しません。私は機能の開始時に警告を出してチェックしました。 私の問題は何ですか?私は何を忘れた? Eclipseは(IS表示をonSubmit)フォームラインにエラーを書き込む: は、関数またはメソッド外部から戻ることができません。また、あなたがname="username"
であなたの入力を与える必要があり
おかげ
コードがレンダリングされていますか? – Phil