How to fill in a text field with drop down selection

前端 未结 1 1962
花落未央
花落未央 2020-12-10 20:46

I have a drop down with different strings, I want a text box to be filled in with the string of the drop down selected.

I am writing this in html

<         


        
相关标签:
1条回答
  • 2020-12-10 21:16

    Something like this jsfiddle demo?

    HTML:

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

    JavaScript:

    <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>
    
    0 讨论(0)
提交回复
热议问题