2
I’m trying to create a dynamic dropdown menu that can show your content 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, the problem I’m having is that when you mark and uncheck the content you don’t always mark correctly and when you uncheck everyone you get the latest checklist.
<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>
You can change that HTML or you don’t have access to it?
– Sergio
I see no problem in changing the HTML, what I am looking for is a solution using checkbox and Dropbox.
– bernlt