关于选择下拉列表后,在输入框中显示所选栏目的值的问题!

cuiyang000 2009-10-20 08:08:40
各位高手好,我现在有这么一个东西



<script>
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name).value;
txt_box.value=field.innerHTML;
}
</script>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select>

<input type="text" name="txt" id="txt" />


我想要的就是当我选择aaa后,在输入框txt中显示123456789,而如果选择了bbb,就显示abcdefg,以此类推.

可是现在我选择后写入的都是undefined,不知何解?
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sohighthesky 2009-10-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ivws_19 的回复:]
HTML code<script>function getValue(value){var txt_box=document.getElementById('txt');
txt_box.value=value;
}</script><selectid="select" name="select" onchange="getValue(this.value)"><optionvalue="1234¡­
[/Quote]
这个简单
cuiyang000 2009-10-20
  • 打赏
  • 举报
回复
谢谢~谢谢~结贴给分!
ivws_19 2009-10-20
  • 打赏
  • 举报
回复

<script>
function getValue(value){
var txt_box=document.getElementById('txt');
txt_box.value=value;
}
</script>
<select id="select" name="select" onchange="getValue(this.value)">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select>

<input type="text" name="txt" id="txt" />

xiaofan_sap 2009-10-20
  • 打赏
  • 举报
回复
<html>

<head>

<title></title>
<script>
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name);

txt_box.value=field.value;
}
</script>

</head>

<body>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select>

<input type="text" name="txt" id="txt" />


</body>

</html>


把value去掉就可以了
BeenZ 2009-10-20
  • 打赏
  • 举报
回复
因为你用错了

<script>
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name).options[0].value;//这里要用选择option
txt_box.value=field;
}
</script>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select>

<input type="text" name="txt" id="txt" />

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧