Vot eshe 1 sposob
<html>
<head>
<script>
function getDayOfWeek() {
var dayOfWeek;
var s = document.getElementById("in1").value;
var date = s.split(".");
console.log(date);
if(isNaN(date[0])==true || parseInt(date[0])>31 || parseInt(date[0])<1)
{document.getElementById("in2").value="error";
return;}
if(isNaN(date[1])==true || parseInt(date[1])>12 || parseInt(date[1])<1)
{document.getElementById("in2").value="error";
return;}
if(isNaN(date[2])==true || parseInt(date[2])>2040 || parseInt(date[2])<1)
{document.getElementById("in2").value="error";
return;}
switch (new Date(date[2], date[1]-1 , date[0]).getDay()) {
case 0:
dayOfWeek = 'Воскресенье';
break;
case 1:
dayOfWeek = 'Понедельник';
break;
case 2:
dayOfWeek = 'Вторник';
break;
case 3:
dayOfWeek = 'Среда';
break;
case 4:
dayOfWeek = 'Четверг';
break;
case 5:
dayOfWeek = 'Пятница';
break;
case 6:
dayOfWeek = 'Суббота';
break;
}
document.getElementById("in2").value=dayOfWeek;
}
</script>
</head>
<body >
<form name="Test">
<input type="text" name="In" id ="in1"><br>
<input type="button" name="Enter" value="День" onclick="getDayOfWeek();">
<input type="text" name="Result" id="in2">
</form>
</body>
</html>
|