Hi:
Rookie in need of help.
I'm trying to call the same function from an onclick of multiple checkboxes so it can add the value to the total when checked (and a descriptive line) and remove it from the total when unchecked.
the start of the function looks like this:
function changeTotal(checkbox,index) {
var text1 = 55.99;
var text2 = 0;
var text3 = 7765.09;
for (i=1; i <=11; i++) {
index=i;
if(index = 1) {
var prodtotal1 = (checkbox.checked,1) ? text1 : text2;
}
if (index = 2) {
var prodtotal2 = (checkbox.checked,2) ? text3 : text2;
}
var prodtotal3 = prodtotal1 + prodtotal2;
if (document.getElementById) {
document.getElementById(12).innerHTML = prodtotal3;
}
else if (document.all) {
document.all[12].innerHTML = prodtotal3;
}
else if (document.layers){
document.layers["ns"+12].document.write(prodtotal3);
document.layers["ns"+12].document.close();
}
}
}
the code for 2 checkboxes in the body looks like this:
<input type="checkbox" name="checkbox" value="checkbox" onclick="changeTotal(this,1);">
<input type="checkbox" name="checkbox" value="checkbox" onclick="changeTotal(this,2);">
I was able to make it work without the index variable and using on 1 checkbox, but not sure how to incorporate 2 or more checkboxes.
Your help would be greatly appreciated.
Thanks,
Rich
Rookie in need of help.
I'm trying to call the same function from an onclick of multiple checkboxes so it can add the value to the total when checked (and a descriptive line) and remove it from the total when unchecked.
the start of the function looks like this:
function changeTotal(checkbox,index) {
var text1 = 55.99;
var text2 = 0;
var text3 = 7765.09;
for (i=1; i <=11; i++) {
index=i;
if(index = 1) {
var prodtotal1 = (checkbox.checked,1) ? text1 : text2;
}
if (index = 2) {
var prodtotal2 = (checkbox.checked,2) ? text3 : text2;
}
var prodtotal3 = prodtotal1 + prodtotal2;
if (document.getElementById) {
document.getElementById(12).innerHTML = prodtotal3;
}
else if (document.all) {
document.all[12].innerHTML = prodtotal3;
}
else if (document.layers){
document.layers["ns"+12].document.write(prodtotal3);
document.layers["ns"+12].document.close();
}
}
}
the code for 2 checkboxes in the body looks like this:
<input type="checkbox" name="checkbox" value="checkbox" onclick="changeTotal(this,1);">
<input type="checkbox" name="checkbox" value="checkbox" onclick="changeTotal(this,2);">
I was able to make it work without the index variable and using on 1 checkbox, but not sure how to incorporate 2 or more checkboxes.
Your help would be greatly appreciated.
Thanks,
Rich