2014年以前または現在の日付以降でない日付をユーザーが入力することを検証する必要があります。 "/"で日付エントリを分割し、[2]のスポットが2014未満だった場合にcatchするためにparseIntを使用しましたが、動作しないようです!問題の検証日入力
<!DOCTYPE HTML>
<html>
<head>
<style>
form {border-style: inset;
\t border-color: blue;
\t height: 360px;
\t width: 775px;
\t margin: auto;
}
\t
</style>
<script>
//Declares 3 arrays
var fullNames = new Array(100);
var dates = new Array(100);
var opinions = new Array(100);
//Global variable
var numOfRatings = 0;
</script>
<script>
//Validates fields are not empty, date is correct then assigns data to arrays
function validateData()
{
\t var fullNameStr = document.getElementById("FullName").value;
\t var dateStr = document.getElementById("Date").value;
\t var opinionStr = document.getElementById("opinion").value;
\t
\t if (!fullNameStr||!opinionStr||!dateStr) {
\t \t alert("Please complete all fields.");
\t return;
\t }
\t else {
\t
\t var dateVal = dateStr;
\t var dateParts = dateVal.split("/");
\t
\t if (parseInt(dateParts[2]) < "2014") {
\t \t \t alert("Invalid date!");
\t \t \t }
\t \t else {
\t \t \t fullNames[numOfRatings] = fullNameStr;
\t \t \t dates[numOfRatings] = dateStr;
\t \t \t opinions[numOfRatings] = opinionStr;
\t \t \t numOfRatings++;
\t \t \t document.getElementById("FullName").value = "";
\t \t \t document.getElementById("Date").value = "";
\t \t \t document.getElementById("opinion").value = "";
\t \t }
\t }
} \t \t
</script>
<script>
//Displays data held in arrays
function displayData()
{
\t var col;
\t var pos;
\t
\t document.getElementById("list").value = "FULL NAME DATE RATING\n";
\t
\t for (pos = 0; pos < numOfRatings; pos++)
\t {
\t \t document.getElementById("list").value += fullNames[pos];
\t \t for (col = fullNames[pos].length; col <= 25; col++)
\t \t \t document.getElementById("list").value += " ";
\t \t document.getElementById("list").value += dates[pos];
\t \t for (col = dates[pos].length; col <= 15; col++)
\t \t \t document.getElementById("list").value += " ";
\t \t document.getElementById("list").value += opinions[pos]+ "\n";
\t }
}
</script>
<script>
//Clears form
function clearData()
{
\t var pos;
\t
\t for (pos = 0; pos < numOfRatings; pos++)
\t {
\t \t fullNames[pos] = "";
\t \t dates[pos] = "";
\t \t opinions[pos] = "";
\t }
\t numOfRatings = 0;
} \t
</script>
</head>
<h1 style ="text-align:center; border-bottom:1px solid #999999">Internet Technologies Membership</h1>
<form name ="ratingForm">
\t <table cellpadding="10">
\t \t <td>
\t \t \t <tr>
\t \t \t \t <td>Full Name:</td>
\t \t \t \t <td><input type="text" id="FullName" name="FullName"></td>
\t \t \t \t <td>Date:</td>
\t \t \t \t <td><input type="date" id="Date" name="Date"></td>
\t \t \t \t <td>Opinion:</td>
\t \t \t \t <td>
\t \t \t \t \t <select name="opinion" id="opinion">
\t \t \t \t \t <option value="★★★★★">Excellent</option>
\t \t \t \t \t <option value="★★★★">Very Good</option>
\t \t \t \t \t <option value="★★★">Good</option>
\t \t \t \t \t <option value="★★">Fair</option>
\t \t \t \t \t <option value="★">Poor</option>
\t \t \t \t \t <option value="0">Very Bad</option>
\t \t \t \t \t </select>
\t \t \t \t </td>
\t \t \t </tr>
\t </table>
<br>
<center>
\t <textarea name="list" id="list" rows="10" cols="100">
\t </textarea>
\t <br>
\t <br>
\t <input type="button" value="RATE" onClick="validateData();">
\t <input type="button" value="DISPLAY" onClick="displayData();">
\t <input type="reset" value="CLEAR" onClick="clearData();">
<br>
</center>
</form>
</html>
それは素晴らしい仕事でした、ありがとう! –