var ile = 1; function plus() { var pole = document.getElementById('pola'); pole.removeChild(pole.getElementsByTagName('input')[ile]); pole.removeChild(pole.getElementsByTagName('input')[ile]); var a = document.createElement('input'); a.type = "file"; a.name = "plik[]"; var b = document.createElement('input'); b.type = "button"; b.onclick = function(){return plus();} b.value = "+"; var c = document.createElement('input'); c.type = "button"; c.onclick = function(){return minus();} c.value = "-"; var d = document.createElement('br'); pole.appendChild(a); pole.appendChild(b); pole.appendChild(c); pole.appendChild(d); ile += 1; } function minus() { var pole = document.getElementById('pola'); pole.removeChild(pole.getElementsByTagName('br')[ile-2]); pole.removeChild(pole.getElementsByTagName('br')[ile-2]); pole.removeChild(pole.getElementsByTagName('input')[ile-1]); pole.removeChild(pole.getElementsByTagName('input')[ile-1]); pole.removeChild(pole.getElementsByTagName('input')[ile-1]); var b = document.createElement('input'); b.type = "button"; b.onclick = function(){return plus();} b.value = "+"; var c = document.createElement('input'); c.type = "button"; c.onclick = function(){return minus();} c.value = "-"; var c2 = document.createElement('input'); c2.type = "button"; c2.onclick = function(){return minus();} c2.value = "-"; c2.disabled = "true"; var d = document.createElement('br'); pole.appendChild(b); if(ile==2) pole.appendChild(c2); else pole.appendChild(c); pole.appendChild(d); ile--; }
Wydaje mi się, że rozumiem w miarę ideę działania skryptu. Potrzebuję jednak dodać jeszcze pole autor do każdego pliku. Stworzyłem więc
<input type="text" name="autor[]" />
a w skrypcie
var e = document.createElement('input'); e.type = "text"; e.name = "autor[]";
Jednak wtedy całość zaczyna szaleć i działać jak chce - za jednym razem pojawia się nowe pole dla autora, po naciśnięciu + znika, itp. W czym tkwi mój błąd?