![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 6 Pomógł: 0 Dołączył: 6.04.2002 Skąd: Lubaczow Ostrzeżenie: (0%) ![]() ![]() |
Witam!
Napisalem prosty skrypt: Kod <script language="javascript"> var countInputs = 0; function dodajInput() { document.getElementById('inputLayer').innerHTML+='<br /><input name="userfile_'+countInputs+'" type="file" />'; countInputs++; } </script> i formularz do tego: Kod <form enctype="multipart/form-data" method="post"> <div id="inputLayer"> <input type="hidden" name="MAX_FILE_SIZE" value="900000" /> </div> <input type="submit" value="Send File" /> </form> <a href="javascript:dodajInput();">Dodaj pole formularza</a> Problem w tym, że klikając w link dodający nowe pole formularza kasuje mi się wcześniej wpisana wartość w innych polach input. Jak to naprawić? |
|
|
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 6 Pomógł: 0 Dołączył: 10.11.2003 Ostrzeżenie: (0%) ![]() ![]() |
Zmieniasz tekst w divie, a nie tworzysz nowego inputa, do tego sluzy metoda createElement().
Kod function addInput(id) { var oDiv = document.getElementById(id); var oInput = document.createElement("<input type='file'>"); oDiv.appendChild(oInput); return; } a poziej Tym samym sposobem mozna tworzyc dowolnego inputa, tabele, elementy tabeli itp. O to chodzilo? Pozdrowka Serg |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 6 Pomógł: 0 Dołączył: 6.04.2002 Skąd: Lubaczow Ostrzeżenie: (0%) ![]() ![]() |
No, prawie..
![]() Twoja funkcja podczas tworzenia nowego elementu zwracała błąd (przeglądarka Firefox). Dzięki Tobie jednak napisałem to o co mi chodziło, dzięki za nakierowanie ![]() Poniżej cały kod, który działa: Kod var countInputs = 0; function addInput(id) { var oDiv = document.getElementById(id); var inputElement = document.createElement("input"); inputElement.setAttribute("name","userfile_"+countInputs); inputElement.setAttribute("type","file"); oDiv.appendChild(inputElement); countInputs++; } i do tego html: |
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 6 Pomógł: 0 Dołączył: 10.11.2003 Ostrzeżenie: (0%) ![]() ![]() |
A tak, zapomnialem dodac, ze IE.
Standardowo jako parametr metody createElement() podaje sie "input", "td", "tr" itp. A parametry obiektu definiuje sie osobno. IE jest w tym temacie bardziej tolerancyjny i troszke rozleniwia ![]() Pozdrawiam Serg Ten post edytował Serg_ 16.07.2004, 13:21:47 |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 12.06.2025 - 23:48 |