0

I need it to change link6/linkr/linkd to "t" using switch based on "checked", switch is working visual correctly but it doesn`t change link6 to "t"

Anyway switch doesn`t change links to "t"

Using debugger i find out that it doesn`t want to trigger, help me make it triggerable

var link6 = "r";
var linkr = "r";
var linkd = "r";

    function download74() {
document.getElementById('link1' + link6).click();
}   
function download143() {
document.getElementById('link2' + linkr).click();
}
    function download198() {
document.getElementById('link3' + linkd).click();
}
function myFunction74() {
  if (confirm("Вы собираетесь скачать 74 devblog (RustUP)!")) {
    download74();
  } else {
    return 0;
  }
}
function myFunction143() {
  if (confirm("Вы собираетесь скачать 143 devblog (Immortal)!")) {
    download143();
  } else {
    return 0;
  }
}
function myFunction198() {
  if (confirm("Вы собираетесь скачать 198 devblog (TRINITY)!")) {
    download198();
  } else {
    return 0;
  }
}

var value = 0;
    var checkbox1 = document.getElementById("checkbox1");
    checkbox1.checked = value;
    document.getElementById("checkbox1").addEventListener("change", function(element){
            if (element.checked) {
      link6 = "t";
    } else {
      link6 = "r";
    }
    });
    var checkbox2 = document.getElementById("checkbox2");
    checkbox2.checked = value;
    debugger;
    document.getElementById("checkbox2").addEventListener("change", function(element){
            if (element.checked) {
            conslose.log("works");
            linkr = "t";
    } else {
    console.log("dont");
      linkr = "r";
    }
    });
    var checkbox3 = document.getElementById("checkbox3");
    checkbox3.checked = value;
    document.getElementById("checkbox3").addEventListener("change", function(element){
            if (element.checked) {
            linkd = "t";
    } else {
      linkd = "r";
    }
    });
    ```
1

2 Answers 2

0

I did an example. Take a look if works for you:

var checkbox2 = document.getElementById("checkbox2");
checkbox2.checked = value;

checkbox2.addEventListener('change', (event) => {
  if (event.target.checked) {
   linkr = "t";
  } else {
    linkr = "r";
  }
})
Sign up to request clarification or add additional context in comments.

1 Comment

i just made it "onclick' in the html file and it works
0

You are using "if (checkbox1.checked)" in your anonymous change function, but when this code is triggered, the checkbox1 element no longer exists. You need to do "if (this.checked)" or "if (element.checked)" .

4 Comments

` if (this.checked) { link6 = "t"; } else { link6 = "r"; }` doesn`t work too
have you put a "DEBUGGER" to check if the function is triggered?
it doesn`t trigger
So you have other problem. The variable checkbox1 is found? Take a look here: stackoverflow.com/questions/6358673/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.