Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Dynamiczne usuwanie pól
weclaprz
post 25.10.2007, 22:23:41
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 25.10.2007

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


Witam
Szukałem szukałem i nie znalazłem. W szystkich postach jest informacja jak dynam
cznie dodać pola, ale wszędzie brak 
informacji jak konkretne pola usunąć.
Potrzebuje zrobić coś takiego
DODAJ

|POLE INPUT1| POLE INPUT2| USUŃ
|POLE INPUT1| POLE INPUT2| USUŃ
|POLE INPUT1| POLE INPUT2| USUŃ

Gdzie po naduszeniu na środkowe "usuń" znika wiersz ze strony a pozostałe dwa są nadal.
Znalazłem przykład:
Kod
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl-PL">
<head>
<title>Strona z dynamicznym formularzem</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<!-- Nasz kod javascript: -->

<script type="text/javascript">
    window.onload = Laduj;
//        window.onload = Usun;
    function Laduj()
    {
        document.getElementById('add_input').onclick = DodajElement;
    }
    function Usun()
    {
        document.getElementById('add_input').onclick = UsunElement;
    }

    function DodajElement()
    {
        var element1 = document.createElement('input');
        element1.setAttribute('type', 'text');
        var element2 = document.createElement('input');
        element2.setAttribute('type', 'text');
        var usun = document.createElement('input');
        usun.setAttribute('type','submit');
        var br =document.createElement('br');

        var liczba = 0;
        var ilosc = document.forms['add_file'].elements.length;
        for (var i = 0; i < ilosc; i++ )
        {
            if (document.forms['add_file'].elements[i].type == 'text')
            {
                liczba += 1;
            }
        }

        element1.setAttribute('name', 'text1_'+(liczba+1));
        element2.setAttribute('name', 'text2_'+(liczba+1));
        usun.setAttribute('name', 'usun-'+(liczba+1));
        usun.setAttribute('value', 'usuń');
        //element.style.display = "block";
        element1.style.margin= "2px";
        element2.style.margin= "2px";
        //usun.style.display = "block";
        usun.style.margin= "2px";
        document.forms['add_file'].appendChild(element1);
        document.forms['add_file'].appendChild(element2);
        document.forms['add_file'].appendChild(usun);
        document.forms['add_file'].appendChild(br);
    }




    function UsunElement() {
        if(document.forms[’add_file’].lastChild.type == ‘submit’)
            document.forms[’add_file’].removeChild(document.forms[’add_file’].lastChild);
    }
</script>
</head>
<body>
<div><a href="#" id="add_input">dodaj nowe pole typu file</a></div>
<form name="add_file" enctype="multipart/form-data" method="post">
    


</form>    
</body>
</html>


I nie mam pojęcia jak zrobić usuwanie pozycji.

Ten post edytował weclaprz 26.10.2007, 17:43:26
Go to the top of the page
+Quote Post
nexis
post 25.10.2007, 22:36:59
Post #2





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

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


A dodawanie Ci działa? Podany przez Ciebie kod jakoś nic nie robi. Zrób jedno - pomożemy z drugim.


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post
Cienki1980
post 26.10.2007, 08:14:38
Post #3





Grupa: Przyjaciele php.pl
Postów: 1 590
Pomógł: 40
Dołączył: 11.01.2007
Skąd: Centrum

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



Proszę zapoznać się z Tematyką i zasadami panującymi na forum Przedszkole i dodać poprawny tag do tematu.

W innym przypadku wątek zostanie zamknięty.


--------------------
404
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 Wersja Lo-Fi Aktualny czas: 6.07.2025 - 04:42