I am trying to display the selected value from the drop down list in a text field in a wordpress post. But the code its not fetching the values.
<select name="cmbitems" id="cmbitems"><style type="text/javascript">
var select = document.getElementById('cmbitems');
var input = document.getElementById('txtprice');
select.onchange = function() {
input.value = select.value;
}
</script>
<option value="" selected="selected">Select Country</option>
<option value="£0.0">Ireland</option>
<option value="£2.50">United States</option>
<option value="£2.50">United Kingdom</option>
<option value="£2.50">Afghanistan</option>
<option value="£2.50">Albania</option>
<option value="£2.50">Algeria</option>
<option value="£2.50">American Samoa</option>
<option value="£2.50">Andorra</option>
Postage Fee:
<input type="text" name="txtprice" id="txtprice" onClick="checkPrice()">
You have a mistake on script start in first line:
TRy to use the correct script tag instead of
Whenever your drop down value changes it will change the value in input field value. You can go through the following code :
Your html syntax is not valid put
script
tag outsideselect
tag, inside select tag there should be onlyoption
tags.