I'm trying since days and I just cant get this to work. Maybe someone can help :) The idea is, that when user clicks on specific checkbox, a specific div appears. This script will run as snipped. Divs are already existing and cannot be changed, exept the id.
Because there is no regularity between inputs and display, sometimes more input fields, sometimes two divs to display, I thought it's possibly better to assign each manually. This was my "Vacation"-Project and i hope i can get this to work... till work starts :)
Also I'd like this to function with other inputs : textarea, radio, select and input.
The only difference between checkbox element is value="checkbox1"
full element is: <input type="checkbox" name="versuch1" required="" **value="checkbox1"**>
the divs look like this and I can assign id to it:
`<div class="elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-71c1c46" data-id="71c1c46" data-element_type="column" **id="exampleoclumn1"**>
what I have:
`
</script>
// Element id
var checkbox1 = document.getElementTagName("checkbox1");
var checkbox2 = document.getElementTagName("checkbox2");
var checkbox3 = document.getElementTagName("checkbox3");
// Column id
var examplecolumn1 = document.getElementsById("examplecolumn1");
var examplecolumn2 = document.getElementById("examplecolumn2");
var examplecolumn3 = document.getElementById("examplecolumn3");
function updateColumnsDisplay() {
examplecolumn1.style.display = checkbox1.checked ? "block" : "none";
examplecolumn2.style.display = checkbox2.checked ? "block" : "none";
examplecolumn3.style.display = checkbox3.checked ? "block" : "none";
}
// event listeners to checkboxes
checkbox1.addEventListener("change", updateColumnsDisplay);
checkbox2.addEventListener("change", updateColumnsDisplay);
checkbox3.addEventListener("change", updateColumnsDisplay);
`
This was one of the previous attemps:
`
</script>
//element id
var checkbox1 = document.getElementById("checkbox1");
var checkbox2 = document.getElementById("checkbox2");
var checkbox3 = document.getElementById("checkbox3");
//column id
var examplecolumn1 = document.getElementById("examplecolumn1");
var examplecolumn2 = document.getElementById("examplecolumn2");
var examplecolumn3 = document.getElementById("examplecolumn3");
examplecolumn1.addEventListener("change", () => {
if(checkbox1.checked){
example-column1.style.display = "block";
if(checkbox2.checked){
example-column2.style.display = "block";
if(checkbox3.checked){
example-column3.style.display = "block";
}else{
example-column1.style.display = "none";
example-column2.style.display = "none";
example-column3.style.display = "none";
}
})`