Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> appendChild i removeChild nie działa w IE :(
exseerius
post
Post #1





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 31.12.2006

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


Człowiek się męczy, pracuje pisze, sprawdza w FF działa, przechodzi na IE - już nie działa :/

Ktoś mi powie dlaczego ?

Kodzik JS:

  1. var lines = 2;
  2. var maks = 26;
  3. var mini = 6;
  4.  
  5. function AddLine(table){
  6. if (lines == maks) {
  7. alert("Osiągnąłeś maksymalną liczbę dokumentów!\nWygeneruj teraz PDF i przygotuj kolejną checklistę!");
  8. }
  9. else {
  10. var row = document.createElement('tr');
  11. row.setAttribute("id",'dok_'+lines);
  12.  
  13. var cell = document.createElement('td');
  14. var inpt = document.createElement('input');
  15. var cellText = document.createTextNode(lines);
  16.  
  17. cell.appendChild(cellText);
  18. row.appendChild(cell);
  19.  
  20. var cell = document.createElement('td');
  21. var inpt = document.createElement('input');
  22. var cellText = document.createTextNode(lines);
  23.  
  24. inpt.setAttribute("type",'text');
  25. inpt.setAttribute("name","name["+lines+"]");
  26. cell.appendChild(inpt);
  27. row.appendChild(cell);
  28.  
  29. var cell = document.createElement('td');
  30. var inpt = document.createElement('input');
  31. var cellText = document.createTextNode(lines);
  32.  
  33. inpt.setAttribute("type",'text');
  34. inpt.setAttribute("name","doc["+lines+"]");
  35. cell.appendChild(inpt);
  36. row.appendChild(cell);
  37.  
  38. var cell = document.createElement('td');
  39. var inpt = document.createElement('input');
  40. var cellText = document.createTextNode(lines);
  41.  
  42. inpt.setAttribute("type",'text');
  43. inpt.setAttribute("name","uwagi["+lines+"]");
  44. cell.appendChild(inpt);
  45. row.appendChild(cell);
  46.  
  47. document.getElementById(table).appendChild(row);
  48.  
  49. lines++;
  50. }
  51. }
  52.  
  53. function DelLine(table) {
  54. var lp = lines-1;
  55. var tabelka = document.getElementById(table);
  56. var row = document.getElementById('dok_'+lp);
  57. tabelka.removeChild(row);
  58. lines = lp;
  59. alert("DEL: dok_"+lp);
  60. }


i to co w htmlu:

  1. <table id="documents">
  2. <tr>
  3.  
  4. <td>Lp.</td>
  5. <td>Imię i Nazwisko</td>
  6. <td>Typ dokumentu</td>
  7. <td>Uwagi</td>
  8. </tr>
  9.  
  10. <tr>
  11. <td>1</td>
  12.  
  13. <td><input type='text' name='name[1]' value=''></td>
  14. <td><input type='text' name='doc[1]' value=''></td>
  15. <td><input type='text' name='uwagi[1]' value=''></td>
  16. </tr>
  17. </table>
  18.  
  19. <input type="button" onclick="javascript:AddLine('documents');" value="Dodaj">
  20. <input type="button" onclick="javascript:DelLine('documents');" value="Usuń">
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post
Post #2





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




Cytat
Człowiek się męczy, pracuje pisze, sprawdza w FF działa, przechodzi na IE - już nie działa

Człowiek się meczy, stara pomagac na forum a tu przychodzi ci taki i pisze "NIE DZIALA" ....
Napisz co ci nie dziala, czym sie to objawia i takie tam.
Go to the top of the page
+Quote Post
exseerius
post
Post #3





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 31.12.2006

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


A no, za szybko wcisnęło mi się dodaj, bo się spieszyłem.

Pod FF dodaje mi kolejne wiersze tabeli z inputami, a w IE nic nie dodaje, a wiem, ze gdzies one są (np po wywołaniu funkcji POST i sprawdzeniu jakie wartosci się przesyłaja są inputy puste, a ich nie widać i tym samym nie mogę uzupełnić danych... Co robię źle?

Nikt nie wie dlaczego nie wyświetlają mi się wiersze tabeli?

Jak robię ten sam przykład, ale na divach to wszystko działa, ale mi zalezy na tabeli.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Ok, znalazłem rozwiązanie:

  1. function AddLine(table){
  2. if (lines == maks) {
  3. alert("Osiągnąłeś maksymalną liczbę dokumentów!\nWygeneruj teraz PDF i przygotuj kolejną checklistę!");
  4. }
  5. else {
  6. var nazwy = Array('name','doc','uwagi');
  7. var tr = document.getElementById(table).insertRow(-1);
  8.  
  9. for(var i=0;i<=nazwy.length;i++){
  10. var td = tr.insertCell(0);
  11. var inpt = document.createElement('input');
  12. var lpt = document.createTextNode(lines);
  13.  
  14. inpt.setAttribute("type",'text');
  15. inpt.setAttribute("name",nazwy[i-1]+"["+lines+"]");
  16.  
  17. if (i == 0){
  18. td.appendChild(lpt);
  19. }
  20. else {
  21. td.appendChild(inpt);
  22. }
  23. tr.appendChild(td);
  24.  
  25. }
  26.  
  27. lines++;
  28. }
  29. }
  30.  
  31. function DelLine(table) {
  32. var lp = lines-1;
  33. if(lp >= mini) {
  34. var tabelka = document.getElementById(table);
  35. tabelka.deleteRow(lp);
  36. lines = lp;
  37. }
  38. }


I przy okazji troszkę zoptymalizowałem kod, żeby był milszy dla oka i dodawanie kolejnych kolumn również było milsze (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Można zamknąć (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Ten post edytował exseerius 14.10.2008, 17:19:24
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 3.10.2025 - 10:40