window.addEventListener('load', function(){ // 체크박스 초기 let lastChecked = null; let checkBoxes = document.querySelectorAll('.chk-list input[name="type"]'); checkBoxes.forEach(chk => { chk.addEventListener('change', function() { if (this.checked) { lastChecked = this; } }); }); const submitBtn = document.getElementById('submitBtn'); // 문의 이벤트 submitBtn.addEventListener('click' , function(e){ // 기본 이벤트 제거 e.preventDefault(); let checkedBoxes = document.querySelectorAll('.chk-list input[name="type"]:checked'); let typeCheck = checkedBoxes.length; let name = document.getElementById('name'); let company = document.getElementById('company'); let frontEmail = document.getElementById("frontEmail"); let backEmail = document.getElementById("backEmail"); let tel = document.getElementById('tel'); let detail = document.getElementById('detail'); let agree = document.getElementById('agreeChk'); if (typeCheck < 1) { alert("Please select at least one inquiry type."); let focusTarget = lastChecked || checkedBoxes[0] || document.querySelector('.chk-list input[name="type"]'); if (focusTarget) { focusTarget.focus(); } return false; } // if (typeCheck > 2) { // alert("문의유형은 최대 2개까지만 선택이 가능합니다."); // if (lastChecked) { // // lastChecked.checked = false; // lastChecked.focus(); // // lastChecked = null; // } // return false; // } if(name.value === ""){ alert('Please enter your name.'); name.focus(); return false; } // if(company.value === ""){ // alert('회사 및 기관명을 입력해주세요.'); // company.focus(); // return false; // } if (frontEmail.value.trim() === "" || backEmail.value.trim() === "") { alert("Please enter your e-mail address."); frontEmail.focus(); return false; } if(tel.value === ""){ alert('Please enter your contact information(Mobile phone).'); tel.focus(); return false; } if(detail.value === ""){ alert('Please enter your inquiry details.'); detail.focus(); return false; } if(agree.checked === false){ alert('Please agree to the privacy policy.'); agree.focus(); return false; } alert('Your inquiry has been registered.'); location.reload(true); }) }, false);