やりたいこと
jspでjavascript入力チェックをしたいです。
フォームの中が空のときに、エラーが表示されるはずなのに、表示されません。
(条件があってjavascriptが必須です。HTMLのみの記述はNGという制約があります。)
簡単な入力チェックも作れず、四苦八苦しています。
試してみたこと
doument.getElementById(xxx)の部分を排除してみました。
画面遷移はうまくいくので、javascriptが間違っているとしか思えませんが、お手上げ状態です。
java
1コード<script type="text/javascript"> 2<!-- 3 4function formcheck(){ 5 var flag = 0; 6 7 //設定開始(必須にする項目を設定してください) 8 if(document.Form1.userId.value == ""){ 9 flag = 1; 10 document.getElementById('notice-input-1'); 11 } 12 else if(document.Form1.pass.value == ""){ 13 document.getElementById('notice-input-2'); 14 flag = 1; 15 } 16 17 if(flag){ 18 window.alert('ログインIDまたはパスワードが違います。'); 19 return false; 20 } 21 else{ 22 return true; //送信を実行 23 24 } 25} 26 27// --> 28</script> 29<%@ page language="java" contentType="text/html; charset=UTF-8" 30 pageEncoding="UTF-8"%> 31<h1>業務報告システム</h1> 32</head> 33 <body> 34 <form name = "Form1" action="/Sample" method="post" onsubmit="return Check()"><br> 35 36 ユーザーID:<input type="text" name="userId" id="notice-input-1"> <br> 37 パスワード:<input type="text" name="pass" id="notice-input-2"> <br> 38 39 <button type=submit>ログイン</button> 40 </form> 41</body> 42</html>
回答3件
あなたの回答
tips
プレビュー