如果我在下拉框中选择其他选项,如何激活文本框 [英] how to activate a textbox if I select an other option in drop down box
本文介绍了如果我在下拉框中选择其他选项,如何激活文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户选择其他选项,那么在文本框下面应该可以看到他自己喜欢的颜色。
我可以用颜色填充下拉框,但不知道如何在
下拉框中选择其他文本框时显示文本框。我知道,使用JavaScript是可能的,但我对JavaScript很新。任何人都可以请我帮助我
?? ??
这是我在我的html表单中实现的选择选项
< select name =color> // color
< option>选择一种颜色< / option>
< option value =red> RED< / option>
< option value =blue> BLUE< / option>
< option value =others>其他< / option>
< / select>
< input type =textname =colorid =color/>< / td> //这个文本框应该被隐藏//直到在下拉框中选择其他人为止
解决下面是您需要编写的核心JavaScript:
< html>
< head>
< script type =text / javascript>
函数CheckColors(val){
var element = document.getElementById('color');
if(val =='pick a color'|| val =='others')
element.style.display ='block';
else
element.style.display ='none';
}
< / script>
< / head>
< body>
< select name =coloronchange ='CheckColors(this.value);'>
< option>选择一种颜色< / option>
< option value =red> RED< / option>
< option value =blue> BLUE< / option>
< option value =others>其他< / option>
< / select>
< input type =textname =colorid =colorstyle ='display:none;'/>
< / body>
< / html>
suppose I've a 3 options in a drop down box say red , blue, others. If a user select option as an others then below a text box should be visible to wrtie his own favourite color. I can populate the drop down box with colors but do not know how to bring textbox visible on selection of others in the drop-down box. I know that using javascript it is possible to do but I am quite new to javascript. can anybody please help me out??
This is the select option I am implementing in my html form
<select name="color"> // color
<option>pick a color</option>
<option value="red">RED</option>
<option value="blue">BLUE</option>
<option value="others">others</option>
</select>
<input type="text" name="color" id="color" /></td> // this textbox should be hidden //until unless others is selected in the drop down box
解决方案
Below is the core JavaScript you need to write:
<html>
<head>
<script type="text/javascript">
function CheckColors(val){
var element=document.getElementById('color');
if(val=='pick a color'||val=='others')
element.style.display='block';
else
element.style.display='none';
}
</script>
</head>
<body>
<select name="color" onchange='CheckColors(this.value);'>
<option>pick a color</option>
<option value="red">RED</option>
<option value="blue">BLUE</option>
<option value="others">others</option>
</select>
<input type="text" name="color" id="color" style='display:none;'/>
</body>
</html>
这篇关于如果我在下拉框中选择其他选项,如何激活文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文