Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [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
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




a skad wiesz, ze mu sie nie podoba a3? A moze mu chodzi oto:
document.getElementById('suma')
Nigdzie nie widze pola suma (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
Cezar708
post
Post #3





Grupa: Zarejestrowani
Postów: 1 116
Pomógł: 119
Dołączył: 10.05.2005
Skąd: Poznań

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


próbujesz odwołać się do elementu o id="suma" a taki w Twoim formularzu nie istnieje.

PS: co tak naprawdę ma ten skrypt zrobić, bo trochę tu jest zakręcone!
Go to the top of the page
+Quote Post
kuterka
post
Post #4





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

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


AAACzeski blad, dziala
  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 ' <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. function Suma(liczba){
  21. var ilosc= parseInt(liczba);
  22. s = 0;
  23. for (i=1;i<=ilosc;i++)
  24. {
  25. wartosc = parseInt(document.getElementById("a"+i).value);
  26. if (!isNaN(wartosc)) s += wartosc;
  27. }
  28. document.getElementById('ready').value = s;
  29. }
  30.  
  31. </script>
  32. <body>


Teraz naszlo zeby zrobic cos takiego do tego skryptu.Jesli user nacisnie przycisk Continue to chcialbym zeby sie pojawil message z opcjami YES NO jesli wybiore yes to wysyla formularz jesli nie to nic nie rob, czy ma ktos maly przykladzik na cosik takiego

Ten post edytował kuterka 6.09.2007, 13:10:32
Go to the top of the page
+Quote Post
vokiel
post
Post #5





Grupa: Zarejestrowani
Postów: 2 592
Pomógł: 445
Dołączył: 12.03.2007

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


robi to funkcja
  1. confirm();

przyjmuje wartość "true" po kliknięciu OK
i "false" po kliknięciu ANULUJ
Go to the top of the page
+Quote Post

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: 22.08.2025 - 19:35