/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Calculator/Worksheet

Hi all.
I’m trying to build a calculator/worksheet that has 12 lines.
Each line has 3 input fields: 1 for “Code”, 1 for “Value”, and 1 for “Price”.
I named each field according to its line (C1-C12, V1-V12, and P1-P12).
When the user clicks “calculate”, he/she will get a total amount for each line and a grand total at the bottom.

My problem is in dealing with the “Values” fields. If the value = 0, the line pays @ 100% of the line price. BUT if the value = 2, it has to look at every line with a “2” value, find the one with the highest price – pay that one at 100% and the rest that have “2” values @ 50%.

I can’t seem to figure out how to tie these different value fields together.
Any advice will be greatly appreciated. Thanks!!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 14.2006 — function getIndexOfHighestPricedValue2() {
var ele = document.myFormName.elements;
var x, y = 0, z = 0, len = 12;
for(x=1; x<=len; ++x) {
if(Number(ele["V"+x].value) == 2
&& Number(ele["P"+x].value) > y) {
y = Number(ele["P"+x].value);
z = x;
}
}
return z;
}
Copy linkTweet thisAlerts:
@KNIAauthorJun 15.2006 — Wow. Thank you so much phpnovice!
Copy linkTweet thisAlerts:
@phpnoviceJun 15.2006 — You're welcome.

Cheers.
×

Success!

Help @KNIA 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.14,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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