I want an input to start disabled and when the person selects for example a certain select option the input is enabled.
I want an input to start disabled and when the person selects for example a certain select option the input is enabled.
Well you can take this example as the basis:
function verifica(value){
var input = document.getElementById("input");
if(value == 2){
input.disabled = false;
}else if(value == 3){
input.disabled = true;
}
};
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<input type="text" name="input" id="input" disabled>
<br><br>
<select id="options" onchange="verifica(this.value)">
<option value="1" selected>1 - Não interfere</option>
<option value="2">2 - Habilita</option>
<option value="3">3 - Desabilita</option>
</select>
</body>
</html>
option
= Voley
input will be enabled. Use getElementById
to identify each element within the form.
To retrieve the value of the selected option
document.getElementById("jogos").value;
Having this value enable or disable the input.
function validarForm() {
var optionSelect = document.getElementById("jogos").value;
if(optionSelect =="3" ){
document.getElementById("btn").disabled = false;
}else{
document.getElementById("btn").disabled = true;
}
}
<form method="post" action="https://pt.stackoverflow.com/">
<select name="jogos" id="jogos" onchange="validarForm()">
<option value=''>Selecione o esporte</option>
<option value='1'>Futebol</option>
<option value='2'>Tenis</option>
<option value='3'>Voley</option>
</select>
<input type="text" id="btn" disabled>
</form>