/    Sign up×
Community /Pin to ProfileBookmark

Calculating fields…

Hi there…

I’m trying to calculate some fields, but it’s not working well.. ?

I’ve got 3 fields like 17n01, 17n02 and 17n03. The total of the numbers in these fields should be displayed in another field subtotal01.

In my example it’s not calculating correct. E.g. the values are 1,3 and 5. The subtotal should be 9. But in my form is displays 135.

This is my code:

[CODE]
totaal17n01 = document.bestellen.totaal17n01.value;
totaal17n02 = document.bestellen.totaal17n02.value;
totaal17n03 = document.bestellen.totaal17n03.value;

sub01 = (sub01 + totaal17n01 -0);
sub01 = (sub01 + totaal17n02 -0);
sub01 = (sub01 + totaal17n03 -0);

document.bestellen.sub01.value = sub01;
[/CODE]

Can anyone help me?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@avaOct 19.2005 — Sure I can help. All items in the textfields are strings (text) so you need to set them to integers with the ParseInt() function.

Replace: [CODE]sub01 = (sub01 + totaal17n01 -0);
sub01 = (sub01 + totaal17n02 -0);
sub01 = (sub01 + totaal17n03 -0);[/CODE]


With:[CODE]sub01 = parseInt(totaal17n01) + 0 + parseInt(totaal17n02) + parseInt(totaal17n03);[/CODE]And it'll work.
Copy linkTweet thisAlerts:
@maw_webdesignauthorOct 19.2005 — Thnx Ava!!! ?
×

Success!

Help @maw_webdesign spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...