0

the main idea is to try to disable multiple checkboxes using multiple ID'S for example using documentGetElementById

Each id belongs to a checkbox

function main(){
var a = document.getElementById("actual").value;
var b = document.getElementById("destination").value;

if (a == "Jamaica" && b == "Paris"){
document.getElementById("A", "B", "C", "D").disabled = true; // occupied seats
}
}

2 Answers 2

1

You have three options:

1.) Multiple calls

document.getElementById("A").disabled = true;
document.getElementById("B").disabled = true;
// and so on...

2.) Loop over the IDs

["A", "B", "C", "D"].forEach(id => document.getElementById(id).disabled = true)

3.) You find a selector that matches all of them and use document.querySelectorAll. IDs have to be unique, so that won't suffice, but let's say all checkboxes on the page need to be disabled:

document.querySelectorAll("input[type='checkbox']").forEach(elem => elem.disabled = true);

For this option, you can alternatively use other CSS selectors that would select the desired checkboxes, like a class name.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the clarification, I did not know that method. Have a nice day :)
No worries :) Feel free to accept an answer of your liking, so StackOverflow marks this as answered and have a nice day!
1

getElementById takes only one parameter, therefore, you should do:

let ids = ["A", "B", "C", "D"];
for(let i = 0; i < ids.length; i++)
     document.getElementById(ids[i]).disabled = true; // occupied seat

1 Comment

Thanks for the clarification, I did not know that method. Have a nice day :)

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.