Skip to main content
hayleyl39888723
Participant
Nov 13, 2017 3:26 PM UTC
Answered

Java Script for Check box to update text

Hello,

I have 1 checkbox with the name taxable and 2 fields with the name CashPrice and TaxableTotal. And in text1 there is a value.

Now comes my question if i check the checkbox the value of CashPrice needs to be added to the TaxableTotal. There are 8 lines that will needed to be able to be added. I don't know how to begin.

Can someone help me with this script ?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Nov 13, 2017 5:44 PM UTC

OK, that's better. You can use this code as the custom calculation script of your total field:

var total = 0;

for (var i=1; i<=8; i++) {

    if (this.getField("Taxable"+i).value!="Off")

        total+=Number(this.getField("CashPrice"+i).value);

}

event.value = total;

4 replies

try67
Community Expert
Community Expert
Nov 13, 2017 4:08 PM UTC

It's possible, but you need to better explain the situation... Where does "text1" fit into this? What are the names of the 8 fields? Is it 8 pairs of check-boxes and text fields, or something else? Please clarify.

Translate
hayleyl39888723
Participant
Nov 13, 2017 5:28 PM UTC

I apologize in CashPrice there is a value... text1 doesn't fit in this one that was an accident. It is 8 pairs of check boxes and fields. The check boxes are named Taxable1, Taxable2, Taxable3....Taxable8 the text fields are CashPrice1, CashPrice2....CashPrice8.

This is a form used for a purchase order. My goal is to find the total of the equipment that is taxable, so that I can figure the tax in a later box.

By trial and error and lots of reading I have figured out several of the other scripts that I have used, but this one has stumped me.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Nov 13, 2017 5:44 PM UTC

OK, that's better. You can use this code as the custom calculation script of your total field:

var total = 0;

for (var i=1; i<=8; i++) {

    if (this.getField("Taxable"+i).value!="Off")

        total+=Number(this.getField("CashPrice"+i).value);

}

event.value = total;

Translate