The code below
<div class="input-field">
<select id="ramal" multiple name="ramal[]" >
<option value="all" id="check-all" name="all" selected >Todas</option>
<?php
if(count($ramais) > 0){
foreach($ramais as $ramal){
formatRamal($ramal);
}
}
?>
</select>
<label>Tipo</label>
</div>
/*esta função encontra-se em outro arquivo*/
function formatRamal($ramal){
echo "<option class=\"check-ramal\" value=\"$ramal\">$ramal</option>";
}
Form this select with multiple checkbox, which by default looks like this:
Mydifficultyistoupdatethe<optionvalue="all" id="check-all" selected >Todas</option>
so that it appears unchecked when any other value is selected.
The unmarked until done, but does not update on the screen what was done with the following code.
$('#ramal').change(function() {
if($('.check-ramal').is(":checked")){
alert("um ramal espcifico foi selecionado");
$('#check-all').removeAttr("selected");
$('#check-all').update();
}
});
PS * I can not comment on the answers, so I edit here to say that the answers below did not show the
<option value="all" id="check-all" name="all" selected >Todas</option>
unchecked.
But it works the first time the page loads if you put it just like this:
<script>$('#check-all').removeAttr("selected"); </script>
But, I need the selection to be removed only when I select other values from the select and that by default is selected if no other values are marked.