mardi 19 septembre 2017

Exclude all other active IDs in if statement

I am writing a simple function with an if statement redirecting the user based on their choices. Basically, the user sees a couple of options (A, B, C, etc). and the user is redirect to one URL when say A and B are selected, and to another URL when say A and C are selected.

So far, this works, using the following code:

function redirect() {
    if (((document.getElementById('A').classList.contains('active')) == true) && ((document.getElementById('B').classList.contains('active')) == true)) {
        window.location = "https://www.example.com";
    };
};

My problem is that I also want to be able to exclude all other possibilities, meaning that I want to add a clause redirecting the user if A and B are selected, but none of the other options. Is there a way to do this without explicitly listing all other options as ('active')) == false?

Thank you again, and sorry if this question reflects my elementary knowledge of coding.

Aucun commentaire:

Enregistrer un commentaire