Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [js] problem
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
chemik1982
Poniższy kod działa pod operą i firefoxem, niestety pod IE nie specjalnie. Ktoś ma jakiś pomysł?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  3. <script type="text/javascript">
  4. function addElements(num){
  5.  
  6. var oDiv = document.getElementById("testing");
  7. oDiv.parentNode.removeChild(oDiv);
  8.  
  9. var oDiv = document.createElement('div');
  10. oDiv.setAttribute("name","testing");
  11. oDiv.setAttribute("id","testing");
  12. document.getElementById('parent').appendChild(oDiv);
  13.  
  14. for(i=0;i<num;i++){
  15. var oInputFile = document.createElement('input');
  16. oInputFile.setAttribute('type','file');
  17. oInputFile.setAttribute("style","display:block");
  18. document.getElementById('testing').appendChild(oInputFile);
  19. }
  20. }
  21. </head>
  22.  
  23. <select id="sel">
  24. <option onclick="addElements(1)" >1</option>
  25. <option onclick="addElements(2)" >2</option>
  26. <option onclick="addElements(3)" >3</option>
  27. <option onclick="addElements(4)" >4</option>
  28. <option onclick="addElements(5)" >5</option>
  29. <div style="width:500px;height:400px;border:1px solid red;" id="parent">
  30. <div id="testing"></div>
  31. </div>
  32. </body>
  33. </html>
nospor
pierwszy blad jaki rzuca sie w oczy to to, iz onclick nie przypisuje sie dla option, a nalezy to robic dla select. Zapytasz pewnie jak sprawdzic co jest zaznaczone. Prosto: twojselect.selectedIndex.
chemik1982
Dzięki pomogło winksmiley.jpg zmienilem z onclick na onchange. Wklajam cały kod, może się komuś przyda.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  3. <script type="text/javascript">
  4. function addElements(){
  5.  
  6.  
  7. var num = document.getElementById('sel').selectedIndex+1;
  8.  
  9. var oDiv = document.getElementById("testing");
  10. oDiv.parentNode.removeChild(oDiv);
  11.  
  12. var oDiv = document.createElement('div');
  13. oDiv.setAttribute("name","testing");
  14. oDiv.setAttribute("id","testing");
  15. document.getElementById('parent').appendChild(oDiv);
  16.  
  17. for(i=0;i<num;i++){
  18. var oInputFile = document.createElement('input');
  19. oInputFile.setAttribute('type','file');
  20. oInputFile.setAttribute("style","display:block");
  21. document.getElementById('testing').appendChild(oInputFile);
  22. }
  23. }
  24. </head>
  25.  
  26. <select id="sel" onchange="addElements()">
  27. <option value="1">1</option>
  28. <option value="2">2</option>
  29. <option value="3">3</option>
  30. <option value="4">4</option>
  31. <option value="4">5</option>
  32. <div style="width:500px;height:400px;border:1px solid green" id="parent">
  33. <div id="testing"></div>
  34. </div>
  35. </body>
  36. </html>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.