How would I total these? If I add something like:
else if (cb1){ event.value[+=][1]this.getField("Totaldays").value*0;
}
It just extends the answer and doesn't give me the sum. For example:
else if (cb1){ event.value=this.getField("Totaldays").value*0;
}
else if (cb2){ event.value=this.getField("Totaldays").value*30;
}
else if (cb3){ event.value=this.getField("Totaldays").value*20;
}
else if (cb4){ event.value=this.getField("Totaldays").value*0;
}
else if (cb5){ event.value=this.getField("Totaldays").value*40;
}
else if (cb6){ event.value=this.getField("Totaldays").value*0;
}
else if (c7){ event.value=this.getField("Totaldays").value*0;
}
Above is my current code which does not total the numbers, just replaces the previous number with the newly checked box number. enter image description here
This can be simplified quite a bit. Understanding the way the return value of a checkbox works in Acrobat JavaScript is the key.
When the box is checked, it returns the specified value, when it is unchecked, it returns "Off". So, you can set the return value of the box to your rental fee. Also, assuming that the rental duration is the same for all items, the whole thing simplifies to:
var rentaldays = xx // xx is the number of days, not part of this snippet
var rsum = 0 ;
for (var i = 0 ; i < 8 ; i++) {
rsum += this.getField("cb" + i).value.toString.replace(/Off/gim , 0)*1 ;
}
var rentalfee = rentaldays * rsum ; // to be written into a field
and that's about it.