■ユーザーインターフェイス
■ソースコード
js main.js
var birthYear = parseInt(document.getElementById('dead_birth_year').value);
var birthMonth = parseInt(document.getElementById('dead_birth_month').value);
var birthDay = parseInt(document.getElementById('dead_birth_day').value);
var birthYearType = parseInt(document.getElementById('dead_birth_koyomi_type').value);
if (birthYearType === -1) {
} else if (birthYearType === 4) {
birthYear += 2018;
} else if (birthYearType === 3) {
birthYear += 1988;
} else if (birthYearType === 2) {
birthYear += 1925;
} else if (birthYearType === 1) {
birthYear += 1911;
} else if (birthYearType === 0) {
birthYear += 1868;
}
console.log("birthYear:::" + birthYear);
var deadYear = parseInt(document.getElementById('dead_year').value);
var deadMonth = parseInt(document.getElementById('dead_month').value);
var deadDay = parseInt(document.getElementById('dead_day').value);
var deadYearType = parseInt(document.getElementById('dead_koyomi_type').value);
if (deadYearType === -1) {
} else if (deadYearType === 4) {
deadYear += 2018;
} else if (deadYearType === 3) {
deadYear += 1988;
} else if (deadYearType === 2) {
deadYear += 1925;
} else if (deadYearType === 1) {
deadYear += 1911;
} else if (deadYearType === 0) {
deadYear += 1868;
}
console.log("deadYear:::" + deadYear);
var ageAtDeath = deadYear - birthYear;
if ((deadMonth < birthMonth) || (deadMonth === birthMonth && deadDay < birthDay)) {
ageAtDeath -= 1;
}
var resultTextBox = document.getElementById('Age_at_Death');
if (!isNaN(ageAtDeath)) {
var numericValue = Number(ageAtDeath);
if (numericValue >= 0) {
resultTextBox.value = numericValue;
}
} else {
}
}
document.getElementById('dead_birth_koyomi_type').addEventListener('change', calculateAge);
document.getElementById('dead_birth_year').addEventListener('change', calculateAge);
document.getElementById('dead_birth_month').addEventListener('change', calculateAge);
document.getElementById('dead_birth_day').addEventListener('change', calculateAge);
document.getElementById('dead_koyomi_type').addEventListener('change', calculateAge);
document.getElementById('dead_year').addEventListener('change', calculateAge);
document.getElementById('dead_month').addEventListener('change', calculateAge);
document.getElementById('dead_day').addEventListener('change', calculateAge);