Display the selected value of a Drop down list in a text field (javascript)

drop-down-menu, forms, javascript

Solution

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;
}

Here is a link to a jsFiddle demo

Problem

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> ``` 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()"> ``` Thank you for answering

Original source