Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobranie dynamiczne nazw pol zawartych w formularzu, document.formularz.elements[i].name;
Mion
post
Post #1





Grupa: Zarejestrowani
Postów: 105
Pomógł: 6
Dołączył: 7.03.2005

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


Meczę się klika godzin z tak prostą operacja jak pobranie i wydrukowanie nazw pol zawartych w formularzu (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
wywołanie: document.write(pola[1].name); zwraca nazwę pola, ale przejście pętlą wywala błąd:
  1. <script type="text/javascript">
  2. function test()
  3. {
  4. var ile=document.formularz.length
  5. var pola=document.formularz.elements;
  6.  
  7. // Tak jest OK document.write(pola[1].name); //
  8.  
  9. for(i=0; i< ile; i++)
  10. {
  11. document.write(pola[i].name);
  12. }
  13. }
  14. </body>
  15. <form method="post" action="odbierz.php" name="formularz">
  16. <input type="text" name="login">
  17. <br /><input type="text" name="haslo">
  18. <input type="hidden" name="uidnadawcy" value="123" />
  19. <input type="button" onclick="test()" name="button" value="go" />
  20. </form>
  21. Wystapil błąd:
  22. Wiersz 25
  23. Znak 3
  24. Blad 'name' jest pusty lub nie jest obiektem
Co tu mam zle w tym tak prostym kodzie (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) POMOCY
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gekon
post
Post #2





Grupa: Zarejestrowani
Postów: 614
Pomógł: 7
Dołączył: 10.11.2003
Skąd: Rzeszów/Kraków

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


  1. function test() {
  2. var pola = document.getElementById('formularz').childNodes;
  3. var akapit = document.createElement("p");
  4.  
  5. document.getElementById('results').appendChild(akapit);
  6.  
  7. for(i=0; i< pola.length; i++){
  8. if(pola[i].name){
  9. var tekst = document.createTextNode(pola[i].name+' ') ;
  10. akapit.appendChild(tekst);
  11. }
  12. }
  13. }


  1. <form method="post" action="odbierz.php" id="formularz">
  2. <input type="text" name="login">
  3. <br /><input type="text" name="haslo">
  4. <input type="hidden" name="uidnadawcy" value="123" />
  5. <input type="button" id="onclick" name="button" value="go" />
  6. <textarea name="test"></textarea>
  7. </form>
  8.  
  9. <div id="results">
  10. </div>
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: 15.10.2025 - 19:10