Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dodawanie elementów formularza, Dynamiczne...
mike
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Jestem w takiej sytuacji: nie znam JS a potrzebuję uzyskać następujący efekt.
Mam formularz:
Kod
+----------------------------------------+
|                FORMULARZ               |
|                                        |
|  [button_1/link_1]                     |
|                                        |
|  +------------+                        |
|  | input/text |  [button_2/link_2]     |
|  +------------+                        |
|                                        |
|             +------------+             |
|             |input/submit|             |
|             +------------+             |
+----------------------------------------+

I teraz kliknięcie dowolną ilość razy w [button_1/link_1], powoduje :
Kod
+----------------------------------------+
|                FORMULARZ               |
|                                        |
|  [button_1/link_1]                     |
|                                        |
|  +------------+                        |
|  | input/text |  [button_2/link_2]     |
|  +------------+                        |
|                                        |
|  +------------+                        |
|  | input/text |  [button_3/link_3]     |
|  +------------+                        |
|                                        |
|                 .                      |
|                 .                      |
|                 .                      |
|                                        |
|  +------------+                        |
|  | input/text |  [button_N/link_N]     |
|  +------------+                        |
|                                        |
|             +------------+             |
|             |input/submit|             |
|             +------------+             |
+----------------------------------------+

i.t.d
Teraz kliknięcie w króryś [button_N/link_N] ( N - numerek input/text ) powoduje usunięcie go z listy.

Proszę o pomoc.

P.S. Sporo się naklepałem żeby ten rysunek zrobić (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) , więc nie mówcie proszę że się nie da tego osiągnąć (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

Ten post edytował mike_mech 21.02.2005, 09:48:30
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Paul
post
Post #2





Grupa: Zarejestrowani
Postów: 636
Pomógł: 0
Dołączył: 22.10.2003
Skąd: Katowice

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


Kod
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">
<style type="text/css">
.inpt{margin-right: 2px;}
.dv{margin:2px;}
</style>
<script type="text/javascript">
ilosc_inputow = 1;
function dodaj(obj) {

    inpt = document.createElement('input');
    inpt.type = 'text';
    inpt.name = 'input' + ++ilosc_inputow;
    inpt.className = 'inpt';
    inpt.value = ilosc_inputow; // numerki w inputach
    
    btn = document.createElement('input');
    btn.type = 'button';
    btn.value = 'Usuń';
    
    dv = document.createElement('div');
    dv.className = 'dv';
    dv.id = 'div' + ilosc_inputow;
    
    eval("btn.onclick = function () { usun('" + dv.id + "', this); }");
    
    dv.appendChild(inpt);
    dv.appendChild(btn);
    obj.form.appendChild(dv);
    
    document.getElementById('ilosc_inputow').value = ilosc_inputow;
}
function usun(dv, obj) {
    objs = obj.form.getElementsByTagName('div');
   for(i = 0; i < objs.length; i++) {
      if(objs[ i ].id == dv) {
         obj.form.removeChild(objs[ i ]);
      }  
   }
}
</script>
</head>
<body>
<form>
<input type="hidden" id="ilosc_inputow" name="ilosc_inputow">
<input type="button" value="Dodaj" onclick="dodaj(this);"><br><br>
<div class="dv" id="div1"><input type="text" id="input1" class="inpt" value="1"><input type="button" value="Usuń" onclick="usun('div1', this);"></div>
</form>
</body>
</html>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 08:13