【うるう年対応】動的に変化する和暦入力フォーム【力技】


おまけで西暦も…

```lang:和暦入力jsp

<%@ page language="java" contentType="text/html; charset=Shift_JIS"
	pageEncoding="Shift_JIS"%>
<%@ page import ="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>Insert title here</title>
<script type="text/javascript">
	window.onload = wareki;
	var now_year = new Date().getFullYear();
	var wareki;
	var hyear = 5;
	var syear = 5;
	var tyear = 5;
	var myear = 5;
	var seirekis = 5;
	var seirekie = 5;
	var gengou = document.getElementsById("gengou");
	var month;

	function wareki(wareki) {
		//初期化
		document.getElementById("hyear").style.display = "";
		document.getElementById("syear").style.display = "none";
		document.getElementById("tyear").style.display = "none";
		document.getElementById("myear").style.display = "none";
		document.getElementById("day31").style.display = "";
		document.getElementById("day30").style.display = "none";
		document.getElementById("day29").style.display = "none";
		document.getElementById("day28").style.display = "none";
		document.getElementById("sday31").style.display = "";
		document.getElementById("sday30").style.display = "none";
		document.getElementById("sday29").style.display = "none";
		document.getElementById("sday28").style.display = "none";
		document.getElementById("eday31").style.display = "";
		document.getElementById("eday30").style.display = "none";
		document.getElementById("eday29").style.display = "none";
		document.getElementById("eday28").style.display = "none";


		if (wareki == 4) {//平成
			document.getElementById("hyear").style.display = "";
			document.getElementById("syear").style.display = "none";
			document.getElementById("tyear").style.display = "none";
			document.getElementById("myear").style.display = "none";
		}
		if (wareki == 3) {//昭和
			document.getElementById("hyear").style.display = "none";
			document.getElementById("syear").style.display = "";
			document.getElementById("tyear").style.display = "none";
			document.getElementById("myear").style.display = "none";
		}
		if (wareki == 2) {//大正
			document.getElementById("hyear").style.display = "none";
			document.getElementById("syear").style.display = "none";
			document.getElementById("tyear").style.display = "";
			document.getElementById("myear").style.display = "none";
		}
		if (wareki == 1) {//明治
			document.getElementById("hyear").style.display = "none";
			document.getElementById("syear").style.display = "none";
			document.getElementById("tyear").style.display = "none";
			document.getElementById("myear").style.display = "";
		}
	}

	function huruu(year) {
		hyear = year % 4;
	}
	function suruu(year) {
		syear = year % 4;
	}
	function turuu(year) {
		tyear = year % 4;
	}
	function muruu(year) {
		myear = year % 4;
	}
	
	function wmonth(month) {
		if (month == 2) {
			if (hyear == 0 || syear == 3 || tyear == 1 || myear == 1){
				document.getElementById("day31").style.display = "none";
				document.getElementById("day30").style.display = "none";
				document.getElementById("day29").style.display = "";
				document.getElementById("day28").style.display = "none";
			}else{
				document.getElementById("day31").style.display = "none";
				document.getElementById("day30").style.display = "none";
				document.getElementById("day29").style.display = "none";
				document.getElementById("day28").style.display = "";
			}			
		}else if (month == 4 || month == 6 || month == 9 || month == 11) {
			document.getElementById("day31").style.display = "none";
			document.getElementById("day30").style.display = "";
			document.getElementById("day29").style.display = "none";
			document.getElementById("day28").style.display = "none";
		} else {
			document.getElementById("day31").style.display = "";
			document.getElementById("day30").style.display = "none";
			document.getElementById("day29").style.display = "none";
			document.getElementById("day28").style.display = "none";
		}
	}

function sseireki(year){
	seirekis = year % 4;
}
function smonth(month) {
	if (month == 2) {
		if (seirekis == 0){
			document.getElementById("sday31").style.display = "none";
			document.getElementById("sday30").style.display = "none";
			document.getElementById("sday29").style.display = "";
			document.getElementById("sday28").style.display = "none";
		}else{
			document.getElementById("sday31").style.display = "none";
			document.getElementById("sday30").style.display = "none";
			document.getElementById("sday29").style.display = "none";
			document.getElementById("sday28").style.display = "";
		}			
	}else if (month == 4 || month == 6 || month == 9 || month == 11) {
		document.getElementById("sday31").style.display = "none";
		document.getElementById("sday30").style.display = "";
		document.getElementById("sday29").style.display = "none";
		document.getElementById("sday28").style.display = "none";
	} else {
		document.getElementById("sday31").style.display = "";
		document.getElementById("sday30").style.display = "none";
		document.getElementById("sday29").style.display = "none";
		document.getElementById("sday28").style.display = "none";
	}
}
function eseireki(year){
	seirekie = year % 4;
}
function emonth(month) {
	if (month == 2) {
		if (seirekie == 0){
			document.getElementById("eday31").style.display = "none";
			document.getElementById("eday30").style.display = "none";
			document.getElementById("eday29").style.display = "";
			document.getElementById("eday28").style.display = "none";
		}else{
			document.getElementById("eday31").style.display = "none";
			document.getElementById("eday30").style.display = "none";
			document.getElementById("eday29").style.display = "none";
			document.getElementById("eday28").style.display = "";
		}			
	}else if (month == 4 || month == 6 || month == 9 || month == 11) {
		document.getElementById("eday31").style.display = "none";
		document.getElementById("eday30").style.display = "";
		document.getElementById("eday29").style.display = "none";
		document.getElementById("eday28").style.display = "none";
	} else {
		document.getElementById("eday31").style.display = "";
		document.getElementById("eday30").style.display = "none";
		document.getElementById("eday29").style.display = "none";
		document.getElementById("eday28").style.display = "none";
	}
}
</script>

</head>
<body>
<form name="form">
	<%
		int gengou;
		int year;
		int month;
		int day;
		Date now = new Date();
		int nyear = now.getYear()+1900;
		int nmonth = now.getMonth();
		int nday = now.getDate();
	%>
	<input type="radio" value="1" name="gengou" id="gengou"
		onchange="wareki([this.value])">明治
	<input type="radio" value="2" name="gengou" id="gengou"
		onchange="wareki([this.value])">大正
	<input type="radio" value="3" name="gengou" id="gengou"
		onchange="wareki([this.value])">昭和
	<input type="radio" value="4" name="gengou" id="gengou"
		onchange="wareki([this.value])">平成
	<input type="hidden" name="buffer" value="1">

	<select name="year" id="hyear" onchange="huruu([this.value])">
		<%
		
		
			for (year = 1; year <= 50; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>
	<select name="year" id="syear" onchange="suruu([this.value])">
		<%
			for (year = 1; year <= 63; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>
	<select name="year" id="tyear" onchange="turuu([this.value])">
		<%
			for (year = 1; year <= 14; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>
	<select name="year" id="myear" onchange="muruu([this.value])">
		<%
			for (year = 1; year <= 44; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>年

	<select name="month" id="month" onchange="wmonth([this.value])">
		<%
			for (month = 1; month <= 12; month++) {
		%>
		<option value="<%=month%>"><%=month%></option>
		<%
			}
		%>
	</select>月

	<select name="day" id="day31">
		<%
			for (day = 1; day <= 31; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="day30">
		<%
			for (day = 1; day <= 30; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="day29">
		<%
			for (day = 1; day <= 29; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="day28">
		<%
			for (day = 1; day <= 28; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>日
	<br>開始日
	<select name="year" id="year" onchange="sseireki([this.value])">
		<%
			for (year = nyear; year <= 2050; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>年
	<select name="month" id="month" onchange="smonth([this.value])">
		<%
			for (month = 1; month <= 12; month++) {
		%>
		<option value="<%=month%>"><%=month%></option>
		<%
			}
		%>
	</select>月
	<select name="day" id="sday31">
		<%
			for (day = 1; day <= 31; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="sday30">
		<%
			for (day = 1; day <= 30; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="sday29">
		<%
			for (day = 1; day <= 29; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="sday28">
		<%
			for (day = 1; day <= 28; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>日
	<div id="mankibi">
	<br>終了日
	<select name="year" id="year" onchange="eseireki([this.value])">
		<%
			for (year = nyear; year <= 2050; year++) {
		%>
		<option value="<%=year%>"><%=year%></option>
		<%
			}
		%>
	</select>年
	<select name="month" id="month" onchange="emonth([this.value])">
		<%
			for (month = 1; month <= 12; month++) {
		%>
		<option value="<%=month%>"><%=month%></option>
		<%
			}
		%>
	</select>月
	<select name="day" id="eday31">
		<%
			for (day = 1; day <= 31; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="eday30">
		<%
			for (day = 1; day <= 30; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="eday29">
		<%
			for (day = 1; day <= 29; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>
	<select name="day" id="eday28">
		<%
			for (day = 1; day <= 28; day++) {
		%>
		<option value="<%=day%>"><%=day%></option>
		<%
			}
		%>
	</select>日
	</div>
</form>
</body>
</html>
```