(function () { const maxTextCount = 200; document.getElementById('questionnaire_area_style').innerHTML = ``; document.getElementById('all_questionnaire_area').innerHTML = `
本アンケートは朝日新聞社の広告事業に関するアンケートです。頂いた回答は広告事業の運営に役立てるほか、本フォーム下部に記載の用途・目的にそって利用いたします。
性別 必須
年代 必須
記事を読んだ感想をお聞かせください 必須
あと200文字まで入力できます。 ※個人情報を含む内容は記入しないでください。
記事で取り上げて欲しいサステナビリティに関するテーマがあればお聞かせください 任意
あと200文字まで入力できます。 ※個人情報を含む内容は記入しないでください。

※頂いた回答は広告事業の運営に役立てるほか、個人を特定できない統計的数値や単体では個人を特定できない情報として広告主などの第三者に提供することがあります。またお客様の興味関心にあわせた情報・サービスの提供や広告配信等のために利用することがあります。
利用者情報の外部送信
※朝日ID会員の回答情報は、上記の利用目的のほか、ご登録の会員情報と紐づけたうえで朝日ID利用規約の第14条に従って利用いたします。
朝日ID会員規約

`; const surveyname = 'sur_611055931'; const targetList = [ { name: 'sur_611055931_001', type: 'radio', required: 'true' } , { name: 'sur_611055931_002', type: 'select', required: 'true' } , { name: 'sur_611055931_003', type: 'textarea', required: 'true' } , { name: 'sur_611055931_004', type: 'text', required: 'false' } ]; function gatherAnswers() { const gatherObj = {}; targetList.forEach(target => { const { name, type } = target; if (type === 'text') { const input = document.getElementsByName(name)[0]; if (input && input.value.length > 0) { gatherObj[name] = input.value; } } else if (type === 'textarea') { const input = document.getElementsByName(name)[0]; if (input && input.textContent.length > 0) { gatherObj[name] = input.textContent; } } else if (type === 'select') { const select = document.getElementsByName(name)[0]; if (select && select.value.length > 0) { gatherObj[name] = select.options[select.selectedIndex].text; } } else if (type === 'radio') { const radioButtons = document.getElementsByName(name); radioButtons.forEach(button => { if (button.checked) { let value = button.value; const otherElement = button.parentElement.parentElement.querySelector('.radio-other-text'); if(otherElement) { value = value + ':' + otherElement.value; } gatherObj[name] = value; } }); } else if (type === 'checkbox') { const checkboxes = document.getElementsByName(name); const checkedValues = []; checkboxes.forEach(checkbox => { if (checkbox.checked) { let value = checkbox.value; const otherElement = checkbox.parentElement.parentElement.querySelector('.checkbox-other-text'); if(otherElement) { value = value + ':' + otherElement.value; } checkedValues.push(value); } }); if (checkedValues.length > 0) { gatherObj[name] = checkedValues.join(', '); } } }); gatherObj['sur_answer'] = surveyname; const urlParams = new URLSearchParams(window.location.search); const testParam = urlParams.get('is_test') === 'true'; if(testParam) { gatherObj['sur_test'] = '1'; } return gatherObj; } function sendSurveyEvent(event, cxj_dmp_params) { if (Object.keys(event).length === 0) { return; } try { cX.sendEvent('survey', event, cxj_dmp_params); } catch (e) { } } function getSurveyData(surveyId) { var surveyData = localStorage.getItem('sur_pnid'); if (surveyData) { surveyData = JSON.parse(surveyData); if (surveyId in surveyData) { return surveyData[surveyId]; } } return null; } function setSurveyData(surveyId, answered) { var surveyData = JSON.parse(localStorage.getItem('sur_pnid') || '{}'); surveyData[surveyId] = answered; localStorage.setItem('sur_pnid', JSON.stringify(surveyData)); } function extractEmailAddresses(text) { const emailPattern = new RegExp('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}', 'g'); const matches = text.match(emailPattern); return matches ? matches : []; }; function extractPhoneNumbers(text) { const phonePattern = new RegExp('(\\+?\\d{1,3}[-.\\s]?)?(\\(?\\d{2,4}\\)?[-.\\s]?)?\\d{2,4}[-.\\s]?\\d{2,4}[-.\\s]?\\d{2,9}', 'g'); const matches = text.match(phonePattern); return matches ? matches : []; }; function validateForm() { let isValid = true; let isTextError = false; const checkboxValidateMap = { }; function showErrorMessage(errorElement, message) { if(message === '') { errorElement.style.display = 'none'; } else { errorElement.style.display = 'block'; errorElement.innerHTML = message; } } for (let targetNo = 0; targetNo < targetList.length; targetNo++) { const targetrequired = targetList[targetNo]; const input = document.getElementsByName(targetrequired.name); if (targetrequired.type === 'textarea' || targetrequired.type === 'text') { const element = input[0]; const value = targetrequired.type === 'text' ? element.value : element.textContent; const parentElement = element.parentElement.parentElement; const errorElement = parentElement.querySelector('div[name=question-alert]'); const emailList = extractEmailAddresses(value); const phoneList = extractPhoneNumbers(value); let errorMessage = ''; if (parentElement.style.display === 'block') { if(emailList.length > 0) { isValid = false; isTextError = true; errorMessage = `メールアドレスが記載されています。個人情報は記載できません。`; } else if(phoneList.length > 0) { isValid = false; isTextError = true; errorMessage = `電話番号が記載されています。個人情報は記載できません。`; } else if (value.length > maxTextCount) { isValid = false; isTextError = true; errorMessage = `${maxTextCount}文字より多く入力することはできません。`; } else { errorMessage = ''; } showErrorMessage( errorElement , errorMessage ); } } if (targetrequired.required === 'true') { if (targetrequired.type === 'radio') { const element = input[0]; const parentElement = element.parentElement.parentElement.parentElement.parentElement.parentElement; const errorElement = parentElement.querySelector('div[name=question-alert]'); if (parentElement.style.display === 'block') { let errorMessage = ''; for (let j = 0; j < input.length; j++) { const element = input[j]; const otherElement = element.parentElement.parentElement.querySelector('.radio-other-text'); if (element.checked) { if(otherElement){ if(otherElement.value === '') { errorMessage = 'その他を選んでいる場合は、テキストも入力してください。'; } else { errorMessage = ''; } } else { errorMessage = ''; } break; } else { errorMessage = '選択されていません。'; } } if (errorMessage !== '') { isValid = false; } showErrorMessage( errorElement , errorMessage ); } } else if (targetrequired.type === 'textarea' || targetrequired.type === 'text') { const element = input[0]; const value = targetrequired.type === 'text' ? element.value : element.textContent; const parentElement = element.parentElement.parentElement; const errorElement = parentElement.querySelector('div[name=question-alert]'); let errorMessage = ''; if (parentElement.style.display === 'block') { if (value === '') { isValid = false; errorMessage = '入力されていません。'; } else { errorMessage = ''; } if(!isTextError) { showErrorMessage( errorElement , errorMessage ); } } } else if (targetrequired.type === 'select') { const element = input[0]; const parentElement = element.parentElement.parentElement.parentElement; const errorElement = parentElement.querySelector('div[name=question-alert]'); let errorMessage = ''; if (parentElement.style.display === 'block') { if (element.selectedIndex === 0) { isValid = false; errorMessage = '選択されていません。'; } else { errorMessage = ''; } showErrorMessage( errorElement , errorMessage ); } } else if (targetrequired.type === 'checkbox') { const checkName = Object.keys(checkboxValidateMap).map(function(key) { return targetrequired.name.indexOf(key) >= 0 ? key : null; }).filter((value) => value)[0]; const element = input[0]; const otherElement = element.parentElement.parentElement.querySelector('.checkbox-other-text'); const parentElement = element.parentElement.parentElement.parentElement.parentElement.parentElement; const errorElement = parentElement.querySelector('div[name=question-alert]'); checkboxValidateMap[checkName].display = parentElement.style.display === 'block'; checkboxValidateMap[checkName].error = errorElement; if (element.checked) { if(otherElement) { if(otherElement.value !== '') { checkboxValidateMap[checkName].num += 1; } } else { checkboxValidateMap[checkName].num += 1; } } } } } Object.keys(checkboxValidateMap).map(function(key) { const checkInfomation = checkboxValidateMap[key]; let message = ''; if(checkInfomation.display && checkInfomation.required) { if (checkInfomation.min) { if(checkInfomation.min > checkInfomation.num) { isValid = false; message = `${checkInfomation.min}個以上選択してください。`; } } if (checkInfomation.max) { if(checkInfomation.max === checkInfomation.min && checkInfomation.max !== checkInfomation.num) { isValid = false; message = `${checkInfomation.max}個選択してください。`; } else if(checkInfomation.num === 0 || checkInfomation.max < checkInfomation.num) { isValid = false; message = `${checkInfomation.max}個以下選択してください。`; } } showErrorMessage( checkInfomation.error , message ); } }); return isValid; } const finishType = 'thanks'; if (getSurveyData(surveyname)) { if (finishType === 'none') { document.getElementById('questionnaireInner').style.display = 'none'; } else if (finishType === 'thanks') { document.getElementById('questionnaire_description').style.display = 'none'; document.getElementById('formans').style.display = 'none'; const thanksmsg = document.getElementById('formthanks'); thanksmsg.innerHTML = 'ご回答を受け付けました。この度はアンケートへご回答いただき誠にありがとうございました。
貴重なお時間を頂戴いたしましたこと、心より感謝申し上げます。'; } } const options = { rootMargin: '0px', threshold: 0.5 }; const observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const inviewObj = {}; inviewObj['sur_inview'] = surveyname; sendSurveyEvent(inviewObj, cxj_dmp_params); observer.unobserve(entry.target); } }); }, options); const targets = document.querySelectorAll('#questionnaire_form_area'); targets.forEach(target => { observer.observe(target); }); const submitButton = document.getElementById('submitButton'); submitButton.addEventListener('click', function (event) { event.preventDefault(); const formerrormsg = document.getElementById('formerror'); if (validateForm()) { formerrormsg.innerHTML = ''; const thanksmsg = document.getElementById('formthanks'); thanksmsg.innerHTML = `回答を受け付けました。
ご回答ありがとうございました。
※本アンケートに回答完了済みの方にはこちらのメッセージが表示されます。
朝日新聞デジタルトップページはこちら`; const answerObj = gatherAnswers(); document.getElementById('questionnaire_description').style.display = 'none'; document.getElementById('formans').style.display = 'none'; sendSurveyEvent(answerObj, cxj_dmp_params); setSurveyData(surveyname, true); } else { formerrormsg.innerHTML = '必須項目の入力をお願いします。'; } }); document.addEventListener('DOMContentLoaded', function() { document.querySelectorAll('input.radio-other-text').forEach( function(other_text) { other_text.addEventListener('change', function() { const checked = this.value !== ''; this.parentElement.querySelector('.radio-other-option').checked = checked; }); } ); document.querySelectorAll('input.checkbox-other-text').forEach( function(other_text) { other_text.addEventListener('change', function() { const checked = this.value !== ''; this.parentElement.querySelector('.checkbox-other-option').checked = checked; }); } ); function checkInputText(mine, text) { const inputLength = text.length; const counterElement = mine.parentElement.querySelector('span[name=text-counter]'); let message = ''; if(inputLength <= maxTextCount) { message = `あと${maxTextCount - inputLength}文字まで入力できます。`; } else { message = '入力最大数を超えています。'; } counterElement.innerHTML = message; } document.querySelectorAll('input.answer-text').forEach( function(other_text) { other_text.addEventListener('input', function() { checkInputText( this , this.value ); }); } ); document.querySelectorAll('div.answer-textarea').forEach( function(other_text) { other_text.addEventListener('input', function() { checkInputText( this , this.textContent ); }); } ); }); })();