Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js]Tworzenie nowej listy z listy
skowron-line
post 20.11.2007, 09:37:44
Post #1





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

Ostrzeżenie: (0%)
-----


Witam chcialbym utworzyc nowy obiekt typu <select> w oparciu o juz istniejacy, niby dosyc proste ale jednak.
kod
  1. <head>
  2. <script type="text/javascript">
  3. function showOptions(){
  4. var oList = document.getElementById('abc');
  5. var oDiv = document.getElementById('oDiv');
  6. var select = document.createElement('select');
  7. for(var i=0; i<=oList.length; i++){
  8. // alert(oList.options[i].value);
  9. // oListValue = oList.options[i].value;
  10. //oListText = oList.options[i].text;
  11. option = document.createElement('option');
  12. option.setAttribute('value',oList.options[i].value);
  13. var optionText = document.createTextNode(oList.options[i].text);
  14. option.appendChild(optionText);
  15. select.appendChild(option);
  16. }
  17. oDiv.appendChild(select);
  18. }
  19. </script>
  20. </head>
  21. <body onLoad="showOptions();">
  22. <select id="abc">
  23. <option value="a">ab</option>
  24. <option value="b">bc</option>
  25. <option value="c">cd</option>
  26. </select>
  27. <div id="oDiv"></div>
  28. </body>
  29. </html>

problem wyglada nastepujaco.
Kod
Error: oList.options[i] has no properties
Source File: file:///C:/AppServ/www/javascript/selectOptions.html
Line: 13

ale jak odkomentuje alerta to elegancko wywali on wszystkie wartosci tej listy


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.08.2025 - 23:18