在文本字段(javascript)中显示下拉列表的选定值 [英] Display the selected value of a Drop down list in a text field (javascript)
本文介绍了在文本字段(javascript)中显示下拉列表的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
这些是下拉列表中的项目。
For Example: These are the items in a drop down list.
<select name="cmbitems" id="cmbitems">
<option value="price1">blue</option>
<option value="price2">green</option>
<option value="price3">red</option>
</select>
当用户选择蓝色时,我想在下面的文本字段中显示price1的值: / p>
When the user selects blue, i want to display the value of price1 in a text field below:
<input type="text" name="txtprice" id="txtprice" onClick="checkPrice()">
谢谢回答
推荐答案
所有你需要做的是在select.onchange事件处理程序中将输入的值设置为select的值。
All you need to do is set the value of the input to the value of the select, in a select.onchange event handler.
var select = document.getElementById('cmbitems');
var input = document.getElementById('txtprice');
select.onchange = function() {
input.value = select.value;
}
这里是指向jsFiddle演示的链接
Here is a link to a jsFiddle demo
这篇关于在文本字段(javascript)中显示下拉列表的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文