I'm trying to create a dynamic dropdown menu that can display its contents as checkbox is checked.
<!DOCTYPE html>
<html>
<body>
<div id="checkbox">
<label><input type="checkb" value="produto"/>Produto</label><br/>
<label><input type="checkb" value="servico"/>Servicos</label><br/>
<label><input type="checkb" value="outros"/>Outros</label><br/>
</div>
<select name="listaPSO" id="LISTAPSO">
<option value="">--- Select ---</option>
<option value="">----Produto----</option>
<option value="Produto">Celular</option>
<option value="Produto">Tablet</option>
<option value="Produto">TV</option>
<option value="">----Servico----</option>
<option value="Servico">Troca</option>
<option value="Servico">Compra</option>
<option value="">----Outros----</option>
<option value="Outros">Outros A</option>
<option value="Outros">Outros B</option>
</select>
As I mark checkbox, I would like to be able to show in the dropdown menu only the related content, when milestone Product would have to show only the list of products in the menu, as well as service and others, I do not know if this form I am doing is ideal , the problem I'm having is that by checking and unchecking the content does not always mark correctly and unchecking all it gets last list tag.
<script>
$('#checkb').change(function () {
var coffee = document.querySelectorAll('input[type="checkb"]:checked');
var x = document.getElementById('listaPSO');
var options = x.getElementsByTagName('option');
for (i = 0; i < coffee.length; i++) { //Pega os valores checkbox
if (coffee[i].checked) {
if (coffee[i].value == 'produto') {
$("#productList").children('option[value="produto"]').show();
$("#productList").children('option[value="servico"]').hide();
$("#productList").children('option[value="outros"]').hide();
}
if (coffee[i].value == 'servico') {
$("#productList").children('option[value="produto"]').hide();
$("#productList").children('option[value="servico"]').show();
$("#productList").children('option[value="outros"]').hide();
}
if (coffee[i].value == 'outros') {
$("#productList").children('option[value="produto"]').hide();
$("#productList").children('option[value="servico"]').hide();
$("#productList").children('option[value="Non"]').show();
} else {
$("#productList").children('option[value="produto"]').show();
$("#productList").children('option[value="servico"]').show();
$("#productList").children('option[value="outros"]').show();
}
}
}
});
</script>