Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [j] Problem z dostaniem sie do obkietu przez getElementById
kuterka
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 25.11.2006

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


Witam

Czy moze mi ktos pomoc dlaczego wywala mi taki blad w tym skrypcie
Error document.getElementById() is null or not an object
a przeciez istnieje obiekt np a3
  1. <?php
  2.  
  3. echo '<FORM name="cos" action="form.php" method="post"> ';
  4.  
  5. echo '<input type="text" name="a1" id="a1" onChange="Suma(this.form.ile_pol.value)">';
  6. echo '<input type="text" name="a2" id="a2" onChange="Suma(this.form.ile_pol.value)">';
  7. echo '<input type="text" name="a3" id="a3" onChange="Suma(this.form.ile_pol.value)">';
  8. echo '<br><br><br />';
  9. echo '<br> suma: <input type="text" name="ready" id="ready">';
  10.  
  11. $ile_pol=3;
  12. echo '<input type="hidden" name="ile_pol" id="ile_pol" value="'.$ile_pol.'">';
  13.  
  14. //-------------- koniec formularza -------------------------
  15. echo '&nbsp;<br><br><br /><input type="submit" class="fontstyle" name="button" value="Continue" ></p>';
  16.  echo '</FORM>';
  17.  
  18. ?>
  19. <script language="javascript" type="text/javascript">
  20. <!--var a = parseInt(document.getElementById('ile_pol').value);
  21.  
  22. function Suma(liczba){
  23.  var ilosc= parseInt(liczba);
  24. s = 0;
  25. var nazwa = "a"+ilosc;
  26. alert(nazwa);
  27. for (i=1;i<=ilosc;i++){
  28. wartosc = parseInt(document.getElementById(nazwa).value);
  29. if (!isNaN(wartosc)) s += wartosc;
  30. document.getElementById('suma').value = s;
  31. }
  32. }
  33.  
  34. </script>
  35. <body>
  36. </body>
  37. </html>
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 Aktualny czas: 22.08.2025 - 03:53