Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- function populateList(givenID)//givenID from the select tag
- {
- var select = document.getElementById("givenID"),
- listData = ["1","2"];
- for(var i = 0; i < listData.length; i++)
- //Loops through array and creates a new DOM node and appends array contents to the object
- {
- var option = document.createElement("OPTION"),
- txt = document.createTextNode(listData[i]);
- option.appendChild(txt);
- option.setAttribute("value",listData[i]);
- select.insertBefore(option,select.lastChild);
- }
- }
- </script>
- </head>
- <body >
- <select id="slt" whenpageloads="populateList">
- <!--When the page loads the select tag will be populated -->
- <option>
- default
- </option>
- </select>
- </body>
Add Comment
Please, Sign In to add comment