[Solved] Drop down list in java script [closed]


HTML Markup

<select id="dropdown">
    <option>First</option>
    <option>Second</option>
    <option>Third</option>
</select>
<textarea id="textarea"> </textarea>

Javascript

 document.getElementById('dropdown')
    .addEventListener('change', function () {
       console.log(this.value);  
        document.getElementById('textarea').innerHTML += this.value;
    }, false);

Working fiddle here. Hope this helps.

Answer 2:

After you updated your question,

var list1 = document.createElement("select"); 
for(var u=0; u<=20; u++) { 
    var w= document.createElement("option"); 
    var e = document.createTextNode(u); 
    w.appendChild(e); 
    list1 .appendChild(w); 
} 

document.getElementsByTagName('body')[0].appendChild(list1);

list1.onchange = function() { 
    document.getElementsByTagName("input")[0].value=list1.value; 
}

You didn’t add the list1 to the document body. Thats why you couldn’t see the result.

0

solved Drop down list in java script [closed]