I\'m trying to make a form which checks if a certain option is selected from a \"select\" tag. Here is my current HTML:
function yesnoCheck(that) {
if (that.value == "other") {
document.getElementById("ifYes").style.display = "block";
}elseif (that.value == "lada") {
} else {
document.getElementById("ifYes").style.display = "none";
}
}
<select onchange="yesnoCheck(this);">
<option value="">Valitse automerkkisi</option>
<option value="lada">Lada</option>
<option value="mosse">Mosse</option>
<option value="volga">Volga</option>
<option value="vartburg">Vartburg</option>
<option value="other">Muu</option>
</select>
<div id="ifYes" style="display: none;">
<label for="car">Muu, mikä?</label> <input type="text" id="car" name="car" /><br />
</div>
讨论(0)
-
here you go:
function yesnoCheck(that) {
if (that.value == "other") {
alert("check");
document.getElementById("ifYes").style.display = "block";
} else {
document.getElementById("ifYes").style.display = "none";
}
}
<select onchange="yesnoCheck(this);">
<option value="">Valitse automerkkisi</option>
<option value="lada">Lada</option>
<option value="mosse">Mosse</option>
<option value="volga">Volga</option>
<option value="vartburg">Vartburg</option>
<option value="other">Muu</option>
</select>
<div id="ifYes" style="display: none;">
<label for="car">Muu, mikä?</label> <input type="text" id="car" name="car" /><br />
</div>
讨论(0)
-
Check out: Display div if a specific select option value is selected
Also don't use ID use data attributes or value to check comparison.
讨论(0)