Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Dodawanie usuwanie elementow
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
grzesio
Czy istnieje inny sposób aby ten kod: "usuwania dodawania pol" zminimalizowac do minimum ?

  1. <script type="text/javascript">
  2.  
  3. /*
  4.  
  5. posted by JayJay (Grzes)
  6.  
  7. */
  8.  
  9.  
  10. var countInputs = 0;
  11.  
  12.  
  13. function addInput(id)
  14. {
  15.  
  16. var Div = document.getElementById(id);
  17.  
  18. // Utworz 4 elementy
  19. var br = document.createElement("br");
  20. var inputElement0 = document.createElement("input");
  21. var inputElement = document.createElement("input");
  22. var inputElement1 = document.createElement("input");
  23.  
  24.  
  25. inputElement0.setAttribute("name","L"+countInputs);
  26. inputElement0.setAttribute("type","text");
  27. inputElement0.setAttribute("size","3");
  28.  
  29. inputElement.setAttribute("name","imie"+countInputs);
  30. inputElement.setAttribute("type","text");
  31.  
  32.  
  33. inputElement1.setAttribute("name","nazwis"+countInputs);
  34. inputElement1.setAttribute("type","text");
  35.  
  36.  
  37. br.setAttribute("id","br"+countInputs);
  38. inputElement0.setAttribute("id","Lp"+countInputs);
  39. inputElement.setAttribute("id","nazwisko"+countInputs);
  40. inputElement1.setAttribute("id","imie"+countInputs);
  41.  
  42. // Wpisz Liczbe Porzadkowa:
  43. inputElement0.value=countInputs;
  44.  
  45.  
  46. // usuwanie elementu po kliknieciu myszka na pole INPUT
  47. // del_inp = "nazwisko"+countInputs;
  48. // inputElement.onclick=function(){this.parentNode.removeChild(this);};
  49. // inputElement.onclick=function(){Div.removeChild(document.getElementById(del_inp));};
  50.  
  51. Div.appendChild(inputElement0);
  52. Div.appendChild(inputElement);
  53. Div.appendChild(inputElement1);
  54. Div.appendChild(br);
  55.  
  56.  
  57. //wpisz do pola input o nazwie name=licznik LP
  58. // document.formularz.licznik.value=countInputs;
  59.  
  60. //wpisz do pola input o id=licz
  61. document.getElementById("licz").value=countInputs;
  62.  
  63. countInputs++;
  64.  
  65. }
  66.  
  67.  
  68. function removeInput(id)
  69. {
  70.  
  71.  
  72. var Div = document.getElementById(id);
  73.  
  74. countInputs--;
  75.  
  76. del_LP = "Lp"+countInputs;
  77. del_imie = "imie"+countInputs;
  78. del_inp = "nazwisko"+countInputs;
  79. br_inp = "br"+countInputs;
  80.  
  81.  
  82. document.formularz.licznik.value=del_inp;
  83.  
  84. Div.removeChild(document.getElementById(del_LP));
  85. Div.removeChild(document.getElementById(del_inp));
  86. Div.removeChild(document.getElementById(del_imie));
  87. Div.removeChild(document.getElementById(br_inp));
  88.  
  89.  
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. <form name=formularz method="get" action="zapisz.php" enctype="multipart/form-data">
  100. <div id="inputLayer"></div>
  101. <br>
  102. <input type="button" onclick="addInput('inputLayer'); return false;" value="dodaj" />
  103. <input type="button" onclick="removeInput('inputLayer'); return false;" value="usun" />
  104. <input type="submit" value="wyslij" />
  105. <input type="text" id="licz" name=licznik value="" />
  106. </form>
nospor
Czemu dajesz to w dziale PHP, uzywasz bbcode PHP skoro ten skrypt to JavaScript? Przenosze a ty popraw bbcode
gekon
DOMy mają to do siebie, że są duże.
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.