0
私は以下のJavascriptコードを持っています。これにより、日付が空にならないようにすることができますが、クライアントが今日より前の日を選択するのを防ぐためにも必要です。それについてどうすればいいですか?JavaScriptを使用したクライアント側の確認
HTML
<form name="myForm" method="post" action="http://www.randyconnolly.com/tests/process.php" onsubmit="return submitFunction()">
<table border="1" >
<tr>
<td>Date:</td>
<td><input type="date" name="date" id="date"></td>
</tr>
<tr>
<td><input type="Submit" value="Submit"></td><td>Click Submit to validate this form!</td>
</tr>
</table>
Javascriptを
function submitFunction(myForm)
{
var errormessage =""; // Generates Error Message if true
/*Manages a control that allows the errormessage variable to determine*
whether or not it has been deemed true. If true, an error message will appaear
If false, the code will continue to move along and validate the data. */
if (document.getElementById('date').value=="")
{
errormessage+="Select a valid date \n";
document.getElementById('date').style.borderColor="red";
}
else {
document.getElementById('date').style.borderColor="green";
}
if(errormessage!="")
{
alert(errormessage);
return false;
}
}
JSFiddleでチェックしても機能しましたが、コードでは機能しませんでした。たぶん私はあなたにHTMLの部分を提供すれば助けになるでしょう。HTMLは以下の通りです: このフォームを検証するには[Submit]をクリックしてください! – Kaky
@Kakyあなたの 'html'にマッチするようにJSFiddleを更新しました。 –
が動作しない:( – Kaky