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
}