如何使用javascript在文本框中显示选定的下拉文本。 [英] how can i display selected dropdown text in textbox using javascript.
本文介绍了如何使用javascript在文本框中显示选定的下拉文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请任何人可以帮助我。新的.net帮助我......
解决方案
如果你有一个看起来像这样的选择元素:
< select id = ddlViewBy跨度>>
< option value = 1> test1 < / 选项 >
< option value = 2 selected = selected> test2 < / 选项 < span class =code-keyword>>
< option value = 3 > test3 < / 选项 >
< / 选择 >
运行此代码:
var e = document .getElementById( ddlViewBy 跨度>);
var strUser = e.options [e.selectedIndex] .value;
make strUser如果你真正想要的是test2,那么这样做:
var e = document .getElementById( ddlViewBy 跨度>);
var strUser = e.options [e.selectedIndex] .text;
哪个会使strUser是test2
var parm = document.getElementById(<%= DropDownList1.ClientID%>);
var texte = document.getElementById(<%= txtzip.ClientID%>);
texte.value = parm.options [parm.selectedIndex] .text;
尝试这会帮助你
< textarea id = mytext > < / textarea >
< 选择 id = 下拉列表 >
< 选项 value = > 无< / option >
< 选项 value = text1 > text1 < / option >
< 选项 value = text2 > text2 < / option >
< 选项 value = text3 > text3 < / option >
< 选项 value = text4 > text4 < / option >
< / select >
< script type = text / javascript< /跨度>>
var mytextbox = document .getElementById(' mytext');
var mydropdown = document .getElementById(' dropdown');
mydropdown.onchange = function (){
mytextbox.value = mytextbox.value + 此跨度>。价值; // 要上架
// mytextbox.innerHTML = this.value;
}
< / script>
pls any one can help me.iam new to .net help me......
解决方案
If you have a select element that looks like this:
<select id="ddlViewBy"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select>
Running this code:
var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].value;
Would make strUser be 2. If what you actually want is test2, then do this:
var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].text;
Which would make strUser be test2
var parm = document.getElementById("<%=DropDownList1.ClientID %>"); var texte = document.getElementById("<%=txtzip.ClientID %>"); texte.value = parm.options[parm.selectedIndex].text;
try this it will help you
try this...:)
<textarea id="mytext"></textarea> <select id="dropdown"> <option value="">None</option> <option value="text1">text1</option> <option value="text2">text2</option> <option value="text3">text3</option> <option value="text4">text4</option> </select>
<script type="text/javascript"> var mytextbox = document.getElementById('mytext'); var mydropdown = document.getElementById('dropdown'); mydropdown.onchange = function(){ mytextbox.value = mytextbox.value + this.value; //to appened //mytextbox.innerHTML = this.value; } </script>
这篇关于如何使用javascript在文本框中显示选定的下拉文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文