Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [HTML]podwajanie ilości w drugim polu
nowy16
post 21.04.2011, 10:04:48
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 0
Dołączył: 29.08.2009

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


Witajcie! Mam taki skrypt:
  1. <input type="text" id="pole_1" onkeyup="getElementById('pole_2').value = this.value" />
  2. <input type="text" id="pole_2" />
  3.  


Jak zrobić aby po wpisaniu w pole1 wartości np 100 to w drugim podwoiłoby tę liczbę np 2 razy. Bardzo bym prosił o gotowe rozwiązanie i z góry dziękuję smile.gif
Go to the top of the page
+Quote Post
ToAr
post 21.04.2011, 10:13:20
Post #2





Grupa: Zarejestrowani
Postów: 49
Pomógł: 18
Dołączył: 7.04.2011
Skąd: Toruń

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


wykorzystać bibliotekę jQuery

w sekcji head dodaj plik biblioteki

  1. <script type="text/javascript" src="js/jquery.min.js"></script>


oraz

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $("#pole_1").keyup(function() {
  4. var pole_1 = $(this).val();
  5. var pole_2 = pole_1 * 2;
  6. $("#pole_2").attr("value", pole_2);
  7. });
  8. });
  9. </script>


no i inputy

  1. <input type="text" id="pole_1">
  2. <input type="text" id="pole_2">


Ten post edytował ToAr 22.04.2011, 08:12:39
Go to the top of the page
+Quote Post
nowy16
post 21.04.2011, 20:05:49
Post #3





Grupa: Zarejestrowani
Postów: 71
Pomógł: 0
Dołączył: 29.08.2009

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


Zrobiłem jak napisałeś, pobrałem jquery z tej strony : http://docs.jquery.com/Release:jQuery_1.3.2 ale niestety nic nie działa sad.gif
Go to the top of the page
+Quote Post
ToAr
post 22.04.2011, 08:13:07
Post #4





Grupa: Zarejestrowani
Postów: 49
Pomógł: 18
Dołączył: 7.04.2011
Skąd: Toruń

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


poprawiłem funkcje i przetestowałem - śmiga.
Go to the top of the page
+Quote Post

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: 13.08.2025 - 23:03