I am trying to make a simple script that allows once a user checks the "termsChkbx
" input field, then the button "submit"
should get enabled but it does not. I Even try and inside the if statement place an alert function which works once it gets clicked, but not when I try and place the btn.disabled = false;
in it. I am new to JavaScript and would appreciate if you can help me out
HTML
<form>
<section id="makeBooking">
<p style="color: #FF0000; font-weight: bold;" id='termsText'>I have read and agree to the terms and conditions
<input type="checkbox" name="termsChkbx"></p>
<p><input type="submit" name="submit" value="Book now!" disabled></p>
</section>
</form
JavaScript
window.addEventListener('load', function() {
'use strict';
const termsChkbx = document.querySelector('[name="termsChkbx"]')
termsChkbx.onclick = function(){
const btn = document.querySelector("[name='submit']");
if (termsChkbx.checked) {
btn.disabled =false;
}//if
else {
btn.disabled = true;
}//else
}//onclick
});