/    Sign up×
Community /Pin to ProfileBookmark

Sum of form fields

Ok the code goes like this:

// JavaScript Document
function updatesum() {
document.sumario.total.value = (document.sumario.precio[]1.value -0) + (document.sumario.precio[]2.value -0) + (document.sumario.precio[]3.value -0) + (document.sumario.precio[]4.value -0) + (document.sumario.precio[]5.value -0) + (document.sumario.precio[]6.value -0) + (document.sumario.precio[]7.value -0);

I know that the problem here is the field name, but how do i make this work without having to change the names?

I can’t change them because i have many other functions with those names already.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 22.2009 — document.sumario.elements['precio[]1'].value
Copy linkTweet thisAlerts:
@ipslayerauthorNov 22.2009 — still not working look at the live form, here it is.

http://www.foreverchef.com/test/forma.php

and here's my sum code.

http://www.foreverchef.com/test/autosum.js
Copy linkTweet thisAlerts:
@FangNov 22.2009 — updatesum does not have a closing bracket. Check the JavaScript Console.
Copy linkTweet thisAlerts:
@ipslayerauthorNov 23.2009 — I updated the code, but it still dosen't work, the field box dosent show the total.

I also tried using (getElementsByName) and it didn't work either.
Copy linkTweet thisAlerts:
@FangNov 24.2009 — I can not see that updatesum is called anywhere?
Copy linkTweet thisAlerts:
@ipslayerauthorNov 24.2009 — ok, great it works now! thanks.

It's now printing in total (A), but now i need to do a couple other things.

I want to print the same result to field (11)

And i want to make a second sum for fields (1) to (10) and print them on field (12) and them sum (11) + (12) and print it on field (13).
×

Success!

Help @ipslayer 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,
)...