remover selected ao desmarcar checkbox
O código abaixo ao marcar checkbox1 fica selected item1. Até aqui tudo ok. O problema é que ao desmarcar checkbox1 o item1 continua selected . Como remover selected do item1 ao desmarcar checkbox1? Obrigado !
<div style="float:left; margin-right:20px;">
checkbox1<input type="checkbox" id="aprendiz" onclick="myFunctionA();" value="aaa"><br>
checkbox2<input type="checkbox" id="aluno" onclick="myFunctionB()" value="bbb"><br>
</div>
<div style="float:left;">
<select multiple size="2" >
<option id="item1">item1</option>
<option id="item2">item2</option>
</select>
</div>
...
<script>
function myFunctionA(){
var x = document.getElementById("aprendiz").value;
if(x=='aaa'){
document.getElementById("item1").selected=true;
}
}
</script>
<script>
function myFunctionB(){
var x = document.getElementById("aluno").value;
if(x=='bbb'){
document.getElementById("item2").selected=true;
}
}
</script>Discussão (1)
Carregando comentários...