javascript - Show input field only if a specific option is selected -
i'm trying make form checks if option selected "select" tag. here current html:
<select onchange="yesnocheck()"> <option id="nocheck" value="">valitse automerkkisi</option> <option id="nocheck" value="lada">lada</option> <option id="nocheck" value="mosse">mosse</option> <option id="nocheck" value="volga">volga</option> <option id="nocheck" value="vartburg">vartburg</option> <option id="yescheck" value="other">muu</option> </select>
this div element should become visible after "muu" selected:
<div id="ifyes" style="display: none;"> <label for="car">muu, mikä?</label> <input type="text" id="car" name="car" /><br /> </div>
and here javascript i'm trying use:
<script type="text/javascript"> function yesnocheck() { if (document.getelementbyid("yescheck").checked) { document.getelementbyid("ifyes").style.display = "block"; } else { document.getelementbyid("ifyes").style.display = "none"; } } </script>
but it's not working...
here go:
<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 /> <script> function yesnocheck(that) { if (that.value == "other") { alert("check"); document.getelementbyid("ifyes").style.display = "block"; } else { document.getelementbyid("ifyes").style.display = "none"; } } </script>
Comments
Post a Comment