I want to create a dynamic select element where if I choose a certain option and a specific text input field is disabled.
Here is my HTML:
<div class="form-group col-md-2">
<label for="">Tipo de Compra</label>
<select name="" class="form-control" id="tipoCompra" required>
<option value="">Tipo de compra </option>
<option value="Nacional">Nacional</option>
<option value="Exterior">Exterior</option>
</select>
</div>
If the user selects the option "Nacional" I want to make the following input field disabled so they can't enter any value.
<div class="form-group col-md-2">
<label for="fob">Costo Fob</label>
<input type="number" step="00.01" id="fob" name="fob" disabled="false" class="form-control" onchange="Todas();" onkeyup="Todas();" required>
</div>
I'm using JavaScript for my functions and some Jquery, but I don't know how to create a function for this.
This is my function:
function TipoCompra(){
var tipoCompra = document.getElementById('tipoCompra').value;
console.log(tipoCompra);
var fob = document.getElementById('fob');
if (tipoCompra == 'Nacional'){
fob.disable = true;
} else {
fob.disable = false;
}
}
But i dont know how to change the disabled property.