0
Save friends!
I’m trying to create a website where it has several different functions and paths for a user to enjoy. However I see that in the future may end up having much more content than I wish to show the user.
What I’m trying to create right now is this, to make sure that by selecting a Checkbox
a certain line disappears for viewing, in case it is hidden. I am using the following logic
<li id="sobremim2"><a href="../Cadastros/minha_informacao.php">Sobre mim</a></li>
<li><a href="#">Relatorios</a></li>
<li><a href="#">Locação</a></li>
<li><a href="#">Estoque</a></li>
<input type="checkbox" id="sobremim" > Sobre mim
<input type="button" onclick="Sobremim()" value="Enviar">
<script>
function Sobremim(){
if(document.getElementById('sobremim').checked){
("#sobremim2").display('none');
} else {
("#sobremim2").display('block');
}
}
</script>
And to keep the Checkbox by selecting even after leaving the page, I use the following logic.
<script>
document.addEventListener("DOMContentLoaded", function(){
var checkbox = document.querySelectorAll("input[type='checkbox']");
for(var item of checkbox){
item.addEventListener("click", function(){
localStorage.s_item ?
localStorage.s_item = localStorage.s_item.indexOf(this.id+",") == -1
? localStorage.s_item+this.id+","
: localStorage.s_item.replace(this.id+",","") :
localStorage.s_item = this.id+",";
});
}
if(localStorage.s_item){
for(var item of checkbox){
item.checked = localStorage.s_item.indexOf(item.id+",") != -1 ? true : false;
}
}
});
</script>
However the same does not disappear, I would like to find out what ah wrong in my logic.
It worked, thank you very much. I have another question that I did not get to research in depth because of the time. There is some way for a user to check a Checkbox and even after closing the browser and opening again it remains Selected and if I deselect the same it is deselected ?
– Leonardo012
I edited the answer, take a look if that’s right.
– nhtoshiaki
Thanks bro, it helped a lot
– Leonardo012