Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

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?
    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);
    };

Open in new window


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Hi Leakim,
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!