(function () { 'use strict'; const SELECTORS = { inquiryBtn: '#inquiry_btn', companyInput: 'input[name="company"]', sogyotechoCheckbox: 'input[type="checkbox"][name="request[]"][value="sogyotecho"]', sogyotechoChecked: 'input[type="checkbox"][name="request[]"][value="sogyotecho"]:checked', }; const UNDETERMINED_VALUE = '未定'; const WARNING_MESSAGE = '「法人名・屋号」が「未定」と入力されています。ご請求の資料は「創業手帳(起業後のユーザー向け)」でよろしいでしょうか。'; document.addEventListener('DOMContentLoaded', function () { const inquiryBtn = document.querySelector(SELECTORS.inquiryBtn); if (!inquiryBtn) return; const btnWrapper = inquiryBtn.closest('div'); if (!btnWrapper || !btnWrapper.parentNode) return; const companyInput = document.querySelector(SELECTORS.companyInput); if (!companyInput) return; const warning = document.createElement('p'); warning.id = 'company_name_warning'; warning.className = 'c_formAlert_Mitei'; warning.setAttribute('role', 'alert'); warning.style.display = 'none'; warning.textContent = WARNING_MESSAGE; btnWrapper.parentNode.insertBefore(warning, btnWrapper); const isUndetermined = function () { return companyInput.value.trim() === UNDETERMINED_VALUE; }; const isSogyotechoChecked = function () { return !!document.querySelector(SELECTORS.sogyotechoChecked); }; const update = function () { const shouldShow = isUndetermined() && isSogyotechoChecked(); warning.style.display = shouldShow ? 'block' : 'none'; }; companyInput.addEventListener('input', update); companyInput.addEventListener('blur', update); // 「創業手帳」チェックボックスの切替で再判定 const sogyotechoCheckboxes = document.querySelectorAll(SELECTORS.sogyotechoCheckbox); sogyotechoCheckboxes.forEach(function (el) { el.addEventListener('change', update); }); // 初期表示チェック (事業開始月による動的切替後の状態にも対応) update(); }); })();