0
I need to reset a select
through a checkbox
.
The problem is the moment I try to access option
with jQuery.
HTML
<select id="selSub">
<option value="0" >Selecione</option>
<option value="1" >1</option>
<option value="2" >2</option>
</select>
jQuery
$(document).ready(function(){
var checkBox = $("#c1").prop('checked');
$('#divSubIn').hide();
$("#c1").click(function(){
if($('#c1').is(":checked")) {
//IF CHECKED
$('#label1').text("insira uma nova >>");
$('#divSubSel').hide();
$('#divSubIn').show();
$('#selSub').material_select('selectedIndex', 0);
}else{
//IF UNCHECKED
$('#label1').text("Inserir subcategoria nova");
$('#divSubSel').show();
$('#divSubIn').hide();
}
});
});
Within the // IF CHECKED
the fourth element $('#selSub').material_select('selectedIndex', 0);
should return select to normal = <option value="0" >Selecione</option>
.
If you just want to reset select. Just exchange: "$('#selSub'). material_select('selectedIndex', 0);" for: "$('#selSub'). val('0');"
– alan