Guest User

Untitled

a guest
Sep 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <script>
  2. function populateList(givenID)//givenID from the select tag
  3. {
  4. var select = document.getElementById("givenID"),
  5. listData = ["1","2"];
  6.  
  7. for(var i = 0; i < listData.length; i++)
  8. //Loops through array and creates a new DOM node and appends array contents to the object
  9. {
  10. var option = document.createElement("OPTION"),
  11. txt = document.createTextNode(listData[i]);
  12. option.appendChild(txt);
  13. option.setAttribute("value",listData[i]);
  14. select.insertBefore(option,select.lastChild);
  15. }
  16. }
  17. </script>
  18. </head>
  19.  
  20. <body >
  21. <select id="slt" whenpageloads="populateList">
  22. <!--When the page loads the select tag will be populated -->
  23. <option>
  24. default
  25. </option>
  26. </select>
  27. </body>
Add Comment
Please, Sign In to add comment