運用型広告
Google・Yahoo!のリスティング広告はもちろん、Facebook・Instagram・LINE・XなどのSNS広告も運用が可能です。
Web制作
お問い合わせフォームなどでよく使う、同意にチェックを入れないと
送信ボタンが押せないようにする処理の実装方法です。
・確認のチェックボックス
<label class="check"><input type="checkbox" name="agree" value="agreement"><span class="bold">同意しました。</span></label>
・送信ボタン
<input type="submit" name="submit" id="submit" value="確認画面へ進む">
document.addEventListener('DOMContentLoaded', function (event) {
const targetButton = document.getElementById('submit');
const triggerCheckbox = document.querySelector('input[name="agree"]');
targetButton.disabled = true;
targetButton.classList.add('is-inactive');
triggerCheckbox.addEventListener('change', function () {
if (this.checked) {
targetButton.disabled = false;
targetButton.classList.remove('is-inactive');
targetButton.classList.add('is-active');
} else {
targetButton.disabled = true;
targetButton.classList.remove('is-active');
targetButton.classList.add('is-inactive');
}
}, false);
}, false);
JSの仕組み
2行目、3行目で変数を用いチェックボックスと送信ボタンを取得。
4、5行目で送信ボタンのinputに対し無効化するdisabledを設定し、
有効・無効時とでスタイルを変えられるよう
is-inactiveのクラス名を追加します。
6行目以降で、thisにチェックボックスが格納されているので
thisがcheckedになっているかいないかで条件分岐をさせます。
この条件分岐によって
チェックされていればis-inactiveを削除してis-activeのスタイルを適応し、disabledを無効に
チェックされていなければis-activeを削除してis-inactiveのスタイルを適応し、disabledを有効にしています。
ぜひお試しください!
Webマーケティングにおけるパフォーマンス改善のための資料がダウンロードできます。