dポイントプレゼントキャンペーン実施中!

JavaScriptで、ブラウザはNN4.75を使用します。
入力された日付と現在の日付を比較し、現在日付よりも未来の日付だったら
アラートで注意を促したいのですが、もしよければどなたか教えて下さい。
お願い申し上げます。

A 回答 (1件)

とりあえず、簡単なサンプルを…




<html>
<head>
<title>日付チェック</title>
<script language="javascript" type="text/javascript">
<!--
function daycheck(Obj){
var now = new Date();
var chkday = new Date(Obj.year.value, (Obj.month.value - 1), Obj.day.value);
if(now.getTime() < chkday.getTime()){
window.alert(Obj.year.value + '年' + Obj.month.value + '月' + Obj.day.value + '日は、今日より後の日付です!');
return false;
}
}
//-->
</script>
</head>
<body>
<form action="hogehoge" onsubmit="return daycheck(this);">
<input size=4 maxlength=4 name="year">
<input size=2 maxlength=2 name="month">
<input size=2 maxlength=2 name="day">
<input type=submit>
</body>
</html>
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!