I'm developing software, but I can not enable a select. The intent is to check the select enable automatically. How do I do this?
function habilitarSofa() {
var radios = document.getElementsByName("sofa[]");
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
var checked_value = radios[i].value;
if (checked_value == 'sofa[]' || checked_value == 'tempo') {
document.getElementsByName('tempo-sofa').disabled = true;
} else {
document.getElementsByName('tempo-sofa').disabled = false;
}
break;
}
}
}
<center>
<div>
<br />
<span class="name-item">sofá</span>
<br />
<form class="form-inline">
<label class="custom-control custom-checkbox mb-2 mr-sm-2 mb-sm-0">
<input type="checkbox" class="custom-control-input" name="sofa[]" value="2" onclick="habilitarSofa()">
<span class="custom-control-indicator"></span>
</label>
<select class="custom-select mb-2 mr-sm-2 mb-sm-0" id="inlineFormCustomSelect" name="tempo-sofa" disabled="disabled">
<option selected hidden>Selecione</option>
<option value="sofa-1">Menos de 6 meses</option>
<option value="sofa-2">De 6 meses a 2 anos</option>
<option value="sofa-3">Mais de 2 anos</option>
</select>
</form>
</div>
</center>