jeudi 16 juillet 2020

How to Trigger change on Javascript addEventListener after adding checked attribute on checkbox

I'm mixing javascript and jquery in my script..

// js variables
const checkbox1 = document.getElementById('bill-to-different-address-checkbox');
const checkbox3 = document.getElementById('bill-to-shipped-address-checkbox');`

// addeventlistener
if (checkbox1) {
    checkbox1.addEventListener('change', (event) => {
. . . . . 

// eventlistener detected checking checkbox
if (event.target.checked) {
. . . . . 

// eventlistener detected unchecking checkbox
else {
         
if (checkbox3) {
       checkbox3.checked=true;
       $("#bill-to-shipped-address-checkbox").trigger("change");
               }
. . . . .

What I'm needing to do is trigger this change, which is another eventlistener on the same page

    if (checkbox3) {
        checkbox3.addEventListener('change', (event) => {

        if (checkbox1) {
           var checkbox1checked = checkbox1.checked;
           . . . . . 

Which does a bunch of stuff. Not relevant to the question. Debugging this checkbox3.checked=true does check the #bill-to-shipped-address-checkbox checkbox, but $("#bill-to-shipped-address-checkbox").trigger("change"); has no noticeable effect.

What must I do to programatically push the change into that event listener whose checkbox is checked




Aucun commentaire:

Enregistrer un commentaire