Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] Dynamiczne dodawanie pól formularza, + treśc przed nimi.
bobo168
post 8.02.2009, 13:07:15
Post #1





Grupa: Zarejestrowani
Postów: 201
Pomógł: 9
Dołączył: 23.08.2006

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


Witam mam skrypt dodwania pól formularzy, wszystko działa ok tylko że chciałem bym uzyskac coś takiego:
  1. <tr><td> odpowiedz : </td><td><input type="text" name="odp(ilestam)" /></td></tr>

a nie samo : <input type="text" name="odp(ilestam)" />

Próbowałem dodawac do funkcji document.write ale nic to nie daje...

Tu jest kod tej funkcji:

  1. <script type="text/javascript">
  2. window.onload = Laduj;
  3. function Laduj() {
  4. document.getElementById('add_input').onclick = DodajElement;
  5. }
  6. function DodajElement()
  7. {
  8. var element = document.createElement('input');
  9. element.setAttribute('type', 'text');
  10. var liczba = 0;
  11. var ilosc = document.forms['sonda'].elements.length;
  12. for (var i = 0; i < ilosc; i++ )
  13. {
  14. if (document.forms['sonda'].elements[i].type == 'text')
  15. {
  16. liczba += 1;
  17. }
  18. }
  19. element.setAttribute('name', 'odp'+(liczba+1));
  20. element.style.display = "block";
  21. element.style.margin= "2px";
  22. document.forms['sonda'].appendChild(element);
  23.  
  24. }
  25. </script>



Z góry dzięki za pomoc smile.gif

Ten post edytował bobo168 8.02.2009, 13:07:56
Go to the top of the page
+Quote Post

Posty w temacie


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: 19.07.2025 - 03:44