Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [js] problem
chemik1982
post
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 13
Dołączył: 20.03.2007
Skąd: Bydgoszcz

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


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>


--------------------
fitmate.pl - aplikacje internetowe
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




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.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
chemik1982
post
Post #3





Grupa: Zarejestrowani
Postów: 91
Pomógł: 13
Dołączył: 20.03.2007
Skąd: Bydgoszcz

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


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>


--------------------
fitmate.pl - aplikacje internetowe
Go to the top of the page
+Quote Post

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 Aktualny czas: 22.08.2025 - 08:36