Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> dynamicznie dodawane pola <input type=file>
lucks
post
Post #1





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 5.04.2005

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


chciałbym zeby uzytkownik mogł dodać dowolną liczbę zalączników, ale zeby nowe puste pole wyświetlało sie dopiero po załadowaniu poprzedniego, tak aby nie umieszczać na sztywno powiedzmy 10 pol
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




Temat: dynamiczny formularz
i jeszcze mala podpowiedź:
Kod
            var diw = document.getElementById('diw');
            
            var file = document.createElement('input');
            file.type="file";
            diw.appendChild(file);


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

"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
lucks
post
Post #3





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 5.04.2005

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


kurcze w js sobie nie radzę, mozna pobrać gdzies taki skrypcik?
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




No to już musisz poszukać smile.gif najlepiej w wyszukiwarce kojarzącej się z narciarzami winksmiley.jpg


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
lucks
post
Post #5





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 5.04.2005

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


ok mam, udało mi się zrobić samemu (tzn dzięki wam w zasadzie), tylko jeszcze jeden problem chodzi mi o to zeby generowały sie pola z róznymi atrybutami name tak zebym mogł pozniej w php je powyciagac
np.
name=file1
name=file2
itd....


i jeszcze jedno jak zrobić zeby wywoływać funkcję tworzenia pola w momencie gdy zostanie dodany plik do pola stworzonego przez tę funkcje

Kod
function AddFile(){
            var diw = document.getElementById('diw');
            var file = document.createElement('input');
            file.type="file";
            var br = document.createElement("br");
            diw.appendChild(br);
            diw.appendChild(file);    
                      file.onchange=AddFile();        // <- exclamation.gif!!!!!!!!
        }


chciałbym uniknąc buttonów

Ten post edytował lucks 6.07.2006, 09:57:25
Go to the top of the page
+Quote Post
revyag
post
Post #6





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

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


Zrób dodatkową zmienną która będzie zliczać inputy.
Kod
var inums = 0;
function AddFile() {
    var diw = document.getElementById('diw');
    var file = document.createElement('input');
    file.type="file";
    filetype.name='file'+inums;
    inums++;
    var br = document.createElement("br");
    diw.appendChild(br);
    diw.appendChild(file);    
    file.addEventListener('onchange',AddFile(),false);
}


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

------
Go to the top of the page
+Quote Post
lucks
post
Post #7





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 5.04.2005

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


super działa, jeszcze tylko chciałbym uzyć zmiennej inums w php do obracania pętlą zeby zapisać pliki
da rade jakoś ja przekazać z funkcji js do formularza w tym samym pliku?
Go to the top of the page
+Quote Post
revyag
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

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


Można kombinować z nadawaniem wartości jakiemuś ukrytemu polu. Np.
  1. <input type="hidden" id="inums" name="inums" value="" />

Kod
....
inums++;
document.getElementById("inums").value = inums;
......

Wtedy w php, może zrobić tak:
  1. <?php
  2. for($i = 0; $i < $_POST["inums"]; $i++) {
  3. ....
  4. }
  5. ?>


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

------
Go to the top of the page
+Quote Post
lucks
post
Post #9





Grupa: Zarejestrowani
Postów: 143
Pomógł: 0
Dołączył: 5.04.2005

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


o to chodziło, działa super, dzieki
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: 19.08.2025 - 14:37