troubleshooting Question

Prevent "onchange" Event Conflict in JavaScript?

Avatar of 894359
894359Flag for United States of America asked on
Web DevelopmentJavaScript
5 Comments1 Solution107 ViewsLast Modified:
I have the below test javascript code which works:
var EmploymentStatusSelect = document.getElementById('mainForm:cont_appRequest_customers__0_employmentStatus:decoin:appRequest_customers__0_employmentStatus');
EmploymentStatusSelect.onchange = (event) => {
    var esSelVal = event.target.value;
    console.log(" event.target.value ==> " + event.target.value);
    if(esSelVal != ""){
        console.log("EmploymentStatusSelect ==> " + event.target.value);  
    } else {
       console.log("EmploymentStatusSelect will not report");
    }
}
The issue is it prevents the form on the page from functioning properly. There is existing logic on the web app for the onchange event in the form so when certain selections are made, the form dynamically displays other questions. When I introduce my code (above) , the existing dynamic field display breaks. Is there a way to rectify this in my code? I am injecting code via a tag management system so I can't touch the code on the page, I can only change my injected code. Is there a way to fix my code so it won't impact the other onchange logic?

Thanks!
ASKER CERTIFIED SOLUTION
David S.
Consultant & Challenge Subduer
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros