実現したいこと
wordpressでTutor LMSというプラグインを使いe-ラーニングのようなシステムを作っています。
ユーザー登録ページに「利用規約に同意します。」というチェックボックスを作り、
チェックされた場合に登録ボタンが有効化されるようにプラグインに機能追加したいと
思っています。
やってみたこと
【functions.phpに追加したコード】
function my_scripts_method() {
wp_enqueue_script(
'custom_script',
get_stylesheet_directory_uri() . '/test.js', array(), '1.0.0', true );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
【test.jsの内容】
window.addEventListener( 'DOMContentLoaded' , function( e )
{
// 同意するのチェックボックス
const consent_chk = document.getElementsById("consent-chk");
// 送信ボタン
const submit_btn = document.getElementsByName("tutor_register_student_btn");
// チェックボックスの入力イベント
consent_chk.addEventListener('change', () => {
// チェックボックスがあれば無効化をオフ、なければオン
if (consent_chk.checked === true) {
submit_btn.disabled = false;
} else {
submit_btn.disabled = true;
}
});
});
【registration.phpの内容】*追加部分のみ
<div class="tutor-form-col-6"> <div class="tutor-form-group"> <label for="consent-chk"> <?php _e('利用規約に同意します。', 'tutor'); ?> </label> <input type="checkbox" id="consent-chk" name="consent-chk"> </div> </div> <div class="tutor-form-row"> <div class="tutor-form-col-12"> <div class="tutor-form-group tutor-reg-form-btn-wrap"> <button type="submit" name="tutor_register_student_btn" value="register" disabled class="tutor-button"><?php _e( 'Register', 'tutor' ); ?></button> </div> </div> </div>発生している問題・エラーメッセージ
上記の通り、いろいろ調べて見よう見まねで実装してみたのですが
チェックボックスにチェックを入れても、登録ボタンが有効になりません。
また、chromeの「検証」画面のConsole画面を見ると
Uncaught TypeError: document.getElementById is not a function
というエラーメッセージが表示されています。
このエラーメッセージについて調べてみたのですが
具体的な解消法がわからず、こちらで質問させていただきました。
どうぞよろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/26 04:46
2022/06/26 05:17
2022/06/26 21:39 編集