2016-08-19 6 views
0

これはデータを投稿するための私のフォームです。それはすべて入力の点では問題ありません。これは、私のjavascript検証フォームを参照するためのものです。日付のバリデーションを追加するには?

<form action= "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" name="input" id="input"> 
      <br> 
      <table> 
       <tr> 
       <th>Animal Name</th> 
       <td><input type="text" name="ANM_NAME" id="ANM_NAME" maxlength="20"></td> 
       </tr> 
       <tr> 
       <th>Owner Name</th> 
       <td><input type="text" name="OWN_NAME" id="OWN_NAME" maxlength="20"></td> 
       </tr> 
       <tr> 
       <th>Sign in</th> 
       <td><input type="date" name="SIGN_IN" id="SIGN_IN"></td> 
       </tr> 
       <tr> 
       <th>Medication</th> 
       <td><input type="text" name="MEDS" id="MEDS" maxlength="20"></td> 
       </tr> 
       <tr> 
       <th>Special Requirements</th> 
       <td><input type="text" name="SPEC" id="SPEC" maxlength="20"></td> 
       </tr> 
       <tr> 
       <th>Food</th> 
       <td><input type="text" name="FOOD" id="FOOD" maxlength="20"></td> 
       </tr> 
       <tr> 
       <th>Notes</th> 
       <td><input type="text" name="NOTE" id="NOTE" maxlength="20"></td> 
       </tr> 
      </table> 
      <br> 
     <input type="button" id="button" value="Submit"> 
     </form> 

は現在、私は、ボタンの上に、検証のためにこれを持って、それがポップを作成していない場合、彼らはそれが、提出するならば、それは、trueにするvarフラグを設定し、その後、彼らはテキストを持っているかどうかを確認するために、入力タイプのテキストをチェックする]をクリックアップアラート。

ただし、異なる入力タイプを使用しているため、日付の間は機能しません。この検証に日付入力をどのように追加しますか?

答えて

1

あなたは区切り文字を使用して入力するより、その後1種類を選択することができます

<script> 
    $("#button").click(function() { 
    var flag = true; 

    // check all input values 
    $("input[type='text'],input[type='date']").each(function() { 
     if ($(this).val() == "") { 
     flag = false; 
     } 
    }); 

    // submit the form 
    if (flag) { 
     $("form#input").submit() 
    } else { 
     // You should do something here. 
     alert("Please fill all inputs!"); 
    } 
    }); 
</script> 
関連する問題