kod
<html> <head> <script type="text/javascript"> function showOptions(){ var oList = document.getElementById('abc'); var oDiv = document.getElementById('oDiv'); var select = document.createElement('select'); for(var i=0; i<=oList.length; i++){ // alert(oList.options[i].value); // oListValue = oList.options[i].value; //oListText = oList.options[i].text; option = document.createElement('option'); option.setAttribute('value',oList.options[i].value); var optionText = document.createTextNode(oList.options[i].text); option.appendChild(optionText); select.appendChild(option); } oDiv.appendChild(select); } </script> </head> <body onLoad="showOptions();"> <select id="abc"> </select> </body> </html>
problem wyglada nastepujaco.
Kod
Error: oList.options[i] has no properties
Source File: file:///C:/AppServ/www/javascript/selectOptions.html
Line: 13
Source File: file:///C:/AppServ/www/javascript/selectOptions.html
Line: 13
ale jak odkomentuje alerta to elegancko wywali on wszystkie wartosci tej listy