/    Sign up×
Community /Pin to ProfileBookmark

calculation question with multiple forms

Hi people ? I am in a situation where I need to have a javascript which calculates the total price which source from individual checkboxes with values and place it into a textfield which is readonly.

The problem is I current have 1 form per 1 checkbox due to the fact that it is inside the table. Same with the textfield it is in the separate form. Is there a way to get that working? This is the javascript I have so far thanks to the help from “Kor”

what’s in the chkNames are the number of checkboxes I have and they are the names of it. The textfield is inside the form called frmtotalCost, and the name of that textfield is txtTotalCost. I still cannot get it to working ?


———————————————————————————————————————————————————————————————————————

var chkNames=[‘music_chk1′,’music_chk2′,’music_chk3′,’music_chk4′,’music_chk5′,’music_chk6′,’music_chk7′,’music_chk8′,’music_chk9′,’music_chk10′,’music_chk11′,’music_chk12′,’music_chk13′,’music_chk14′,’music_chk15’];

function totalCost(price){
var price2=document[‘frmtotalCost’]
var Current = Number(price2[‘txtTotalCost’].defaultValue);
for(var index=0; index<chkNames.length; index++){
price[chkNames[index]].checked?Current+=Number(price[chkNames[index]].value):null;
}
price2[‘txtTotalCost’].value = Current
}


———————————————————————————————————————————————————————————————————————

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 10.2006 — The problem is I current have 1 form per 1 checkbox due to the fact that it is inside the table. Same with the textfield it is in the separate form.[/QUOTE]
There is no reason to do it that way -- and [I][U]every[/U][/I] reason [B][I][U]not[/U][/I][/B] to do it that way. Just use a [I][U]single[/U][/I] FORM and place the opening FORM tag [I][U]before[/U][/I] the opening of the first table and the closing FORM tag [I][U]after[/U][/I] the close of all tables. This will make your FORM handling [B][I][U]much[/U][/I][/B] easier.
×

Success!

Help @lucifer82 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...