MJ
asked on
Checkbox functionality not captured by event listener?
I have the following code but for some reason the check on line 15 doesn't work? I'm not sure why?
Thanks!
var checkEmailConfirmCheckBox = document.getElementById('PRIMARY_BASIC_INFO_EMAIL-appRequest_primary_emailVerified');
function _dtmCheckOAO4emailConfirmCheckbox(){
checkEmailConfirmCheckBox = document.getElementById('PRIMARY_BASIC_INFO_EMAIL-appRequest_primary_emailVerified');
if(checkEmailConfirmCheckBox != null){
checkEmailConfirmCheckBox.addEventListener('change', trackEmailConfirmationCheckbox);
} else {
setTimeout( _dtmCheckOAO4emailConfirmCheckbox, 500);
}
};
function trackEmailConfirmationCheckbox(){
console.log("==== IN FUNCTION ====");
var emailCB = event.target.value;
if(emailCB.checked){
console.log("==== EMAIL CONF BOX CHECKED ====");
}
checkEmailConfirmCheckBox.removeEventListener('change', trackEmailConfirmationCheckbox);
};
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I only had to change this line:
var emailCB = event.target;
And it works. I'm I risking anything by not passing the event explicitly? Am I opening myself up to possible issues in other browsers? I'm working in Chrome.
Thanks!