Javascript examples for DOM HTML Element:Select
You can create a <select> element by using the document.createElement() method:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">create a SELECT and an OPTION element</button> <script> function myFunction() {// ww w.j a v a2 s . c om var x = document.createElement("SELECT"); x.setAttribute("id", "mySelect"); document.body.appendChild(x); var z = document.createElement("option"); z.setAttribute("value", "css"); var t = document.createTextNode("CSS"); z.appendChild(t); document.getElementById("mySelect").appendChild(z); } </script> </body> </html>