Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dodawanie pol
DannyM
post
Post #1





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


  1. var wynik = document.getElementById('stan').value+document.getElementById('oddaje').value

Mam sobie taki skrypcik i ma dodac do stanu pole oddaje.
Wiem, ze to moze zmieszne ale wynikem mam "dodanie" doslowne a nie matematyczne.
Dodaje 10+10 i mam 1010 a nie 20

Ten post edytował DannyM 13.08.2008, 13:29:50
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




Jak dodajesz stringi to co sie dziwisz? (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) value jest stringiem a nie liczbą. jak chcesz miec liczbe to przepusc to przez:
http://www.w3schools.com/jsref/jsref_parseInt.asp
Go to the top of the page
+Quote Post
DannyM
post
Post #3





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 13.08.2008, 14:33:01 ) *
Jak dodajesz stringi to co sie dziwisz? (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) value jest stringiem a nie liczbą. jak chcesz miec liczbe to przepusc to przez:
http://www.w3schools.com/jsref/jsref_parseInt.asp

no pozostale operacje jak - czy * robi poprawnie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #4





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




ale operator + w js ma podwoją rolę: dodaje liczby oraz łączy stringi. Wiec jak dostaje string to nie zastanawia sie czy jest on liczbą czy nie - jest stringiem to łączy i koniec kropka (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
DannyM
post
Post #5





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 13.08.2008, 14:43:55 ) *
ale operator + w js ma podwoją rolę: dodaje liczby oraz łączy stringi. Wiec jak dostaje string to nie zastanawia sie czy jest on liczbą czy nie - jest stringiem to łączy i koniec kropka (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Cholerder dla mnie JS to tak jak C++ moze cos podpowiesz?
Jak mam wpasowac w to pola:
  1. var wynik = document.write(parseInt("pole1") + parseInt("pole2")) ;


Teraz pobieram je po ID

Ten post edytował DannyM 13.08.2008, 13:46:10
Go to the top of the page
+Quote Post
nospor
post
Post #6





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




nie oslabiaj (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Kod
var wynik = parseInt(document.getElementById('stan').value)+parseInt(document.getElementById('oddaje').value);
Go to the top of the page
+Quote Post
DannyM
post
Post #7





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 13.08.2008, 14:46:48 ) *
nie oslabiaj (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Kod
var wynik = parseInt(document.getElementById('stan').value)+parseInt(document.getElementById('oddaje').value);


PIEKNIE DZIEKUJE (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Z caloscy wynikla jeszcze jedna sprawa. Jak uzyskac wartosc w zaokragleniu?
Obecnie mam 13.75 a chce otrzymac 14.00
Go to the top of the page
+Quote Post
skowron-line
post
Post #8





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Kod
Math.round(..);

http://www.javascriptkit.com/javatutors/round.shtml

Ten post edytował skowron-line 25.08.2008, 10:28:22
Go to the top of the page
+Quote Post
DannyM
post
Post #9





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Wlasnie o to chodzilo (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Dzieki
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 - 23:37